summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2012-10-08 12:47:47 +0200
committerStefan Metzmacher <metze@samba.org>2012-10-08 16:13:06 +0200
commit2fce71c89af66c1467f0a18b97e237b307387620 (patch)
tree68397b5d35bae14335859473786c528f8f836ba2 /source4
parent8d4943dcf943dc83b9b663d3d025fb1a8dbcba86 (diff)
downloadsamba-2fce71c89af66c1467f0a18b97e237b307387620.tar.gz
samba-2fce71c89af66c1467f0a18b97e237b307387620.tar.bz2
samba-2fce71c89af66c1467f0a18b97e237b307387620.zip
s4:samba-tool: use normal option parsing in SuperCommand
We use the epilog to print the subcommands. metze
Diffstat (limited to 'source4')
-rw-r--r--source4/scripting/python/samba/netcmd/__init__.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/source4/scripting/python/samba/netcmd/__init__.py b/source4/scripting/python/samba/netcmd/__init__.py
index 677f4f0fc2..a3edf50516 100644
--- a/source4/scripting/python/samba/netcmd/__init__.py
+++ b/source4/scripting/python/samba/netcmd/__init__.py
@@ -201,22 +201,25 @@ class SuperCommand(Command):
return self.subcommands[subcommand]._run(
"%s %s" % (myname, subcommand), *args)
- self.usage(myname)
- self.outf.write("Available subcommands:\n")
+ epilog = "\nAvailable subcommands:\n"
subcmds = self.subcommands.keys()
subcmds.sort()
max_length = max([len(c) for c in subcmds])
for cmd_name in subcmds:
cmd = self.subcommands[cmd_name]
if not cmd.hidden:
- self.outf.write(" %*s - %s\n" % (
- -max_length, cmd_name, cmd.short_description))
- if subcommand in [None]:
- raise CommandError("You must specify a subcommand")
- if subcommand in ['help', '-h', '--help']:
- self.outf.write("For more help on a specific subcommand, please type: %s <subcommand> (-h|--help)\n" % myname)
- return 0
- raise CommandError("No such subcommand '%s'" % subcommand)
+ epilog += " %*s - %s\n" % (
+ -max_length, cmd_name, cmd.short_description)
+ epilog += "For more help on a specific subcommand, please type: %s <subcommand> (-h|--help)\n" % myname
+
+ parser, optiongroups = self._create_parser(myname, epilog=epilog)
+ args_list = list(args)
+ if subcommand:
+ args_list.insert(0, subcommand)
+ opts, args = parser.parse_args(args_list)
+
+ parser.print_help()
+ return -1
class CommandError(Exception):