1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-02 00:22:11 +03:00

s4:samba-tool: use normal option parsing in SuperCommand

We use the epilog to print the subcommands.

metze
This commit is contained in:
Stefan Metzmacher
2012-10-08 12:47:47 +02:00
parent 8d4943dcf9
commit 2fce71c89a

View File

@ -201,22 +201,25 @@ class SuperCommand(Command):
return self.subcommands[subcommand]._run( return self.subcommands[subcommand]._run(
"%s %s" % (myname, subcommand), *args) "%s %s" % (myname, subcommand), *args)
self.usage(myname) epilog = "\nAvailable subcommands:\n"
self.outf.write("Available subcommands:\n")
subcmds = self.subcommands.keys() subcmds = self.subcommands.keys()
subcmds.sort() subcmds.sort()
max_length = max([len(c) for c in subcmds]) max_length = max([len(c) for c in subcmds])
for cmd_name in subcmds: for cmd_name in subcmds:
cmd = self.subcommands[cmd_name] cmd = self.subcommands[cmd_name]
if not cmd.hidden: if not cmd.hidden:
self.outf.write(" %*s - %s\n" % ( epilog += " %*s - %s\n" % (
-max_length, cmd_name, cmd.short_description)) -max_length, cmd_name, cmd.short_description)
if subcommand in [None]: epilog += "For more help on a specific subcommand, please type: %s <subcommand> (-h|--help)\n" % myname
raise CommandError("You must specify a subcommand")
if subcommand in ['help', '-h', '--help']: parser, optiongroups = self._create_parser(myname, epilog=epilog)
self.outf.write("For more help on a specific subcommand, please type: %s <subcommand> (-h|--help)\n" % myname) args_list = list(args)
return 0 if subcommand:
raise CommandError("No such subcommand '%s'" % subcommand) args_list.insert(0, subcommand)
opts, args = parser.parse_args(args_list)
parser.print_help()
return -1
class CommandError(Exception): class CommandError(Exception):