From 2fce71c89af66c1467f0a18b97e237b307387620 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 8 Oct 2012 12:47:47 +0200 Subject: s4:samba-tool: use normal option parsing in SuperCommand We use the epilog to print the subcommands. metze --- source4/scripting/python/samba/netcmd/__init__.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'source4/scripting/python') 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 (-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 (-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): -- cgit