From: Björn Baumbach Date: Tue, 28 Apr 2020 15:09:56 +0000 (+0200) Subject: samba-tool: fetch "no such subcommand" error and print error message X-Git-Tag: ldb-2.2.0~844 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc280f88becc6679cd95bf8914f80812358338cc;p=thirdparty%2Fsamba.git samba-tool: fetch "no such subcommand" error and print error message This patch especially improves the case where extra arguments are used. Without this patch just the attributes are mentioned as invalid, if samba-tool is called with an invalid/unknown subcommand. Example without this patch: # samba-tool sites list --all Usage: samba-tool sites samba-tool sites: error: no such option: --all This can be deceptive for users. Is looks like the "list" command does not provide a "--all" option. Example with this patch: # samba-tool sites list --all samba-tool sites: no such subcommand: list Usage: samba-tool sites (...) Signed-off-by: Björn Baumbach Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Wed Apr 29 08:08:21 UTC 2020 on sn-devel-184 --- diff --git a/python/samba/netcmd/__init__.py b/python/samba/netcmd/__init__.py index 57df46343e9..620e3751e7f 100644 --- a/python/samba/netcmd/__init__.py +++ b/python/samba/netcmd/__init__.py @@ -234,6 +234,9 @@ class SuperCommand(Command): if subcommand in self.subcommands: return self.subcommands[subcommand]._run( "%s %s" % (myname, subcommand), *args) + elif subcommand not in [ '--help', 'help', None ]: + print("%s: no such subcommand: %s\n" % (myname, subcommand)) + args = [] if subcommand == 'help': # pass the request down