From a677d1aab1c72033bae06aded688cab830f54c21 Mon Sep 17 00:00:00 2001 From: Jonas Hoersch Date: Wed, 4 Dec 2013 16:41:58 +0100 Subject: [PATCH 1/2] add --help-all meta-switch for recursive help --- plumbum/cli/application.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plumbum/cli/application.py b/plumbum/cli/application.py index 9d0677125..6b4c480f4 100644 --- a/plumbum/cli/application.py +++ b/plumbum/cli/application.py @@ -11,6 +11,8 @@ class ShowHelp(SwitchError): pass +class ShowHelpAll(SwitchError): + pass class ShowVersion(SwitchError): pass @@ -274,6 +276,8 @@ def _parse_args(self, argv): def _validate_args(self, swfuncs, tailargs): if six.get_method_function(self.help) in swfuncs: raise ShowHelp() + if six.get_method_function(self.helpall) in swfuncs: + raise ShowHelpAll() if six.get_method_function(self.version) in swfuncs: raise ShowVersion() @@ -334,6 +338,8 @@ def run(cls, argv = sys.argv, exit = True): # @ReservedAssignment ordered, tailargs = inst._validate_args(swfuncs, tailargs) except ShowHelp: inst.help() + except ShowHelpAll: + inst.helpall() except ShowVersion: inst.version() except SwitchError: @@ -383,6 +389,20 @@ def cleanup(self, retcode): :param retcode: the return code of ``main()`` """ + @switch(["--help-all"], overridable = True, group = "Meta-switches") + def helpall(self): + """Prints the help messages of all subcommands and quits""" + self.help() + print "\n" + + if self._subcommands: + for name, subcls in sorted(self._subcommands.items()): + subapp = (subcls.get())("%s %s" % (self.PROGNAME, name)) + subapp.parent = self + for si in subapp._switches_by_func.values(): + if si.group == "Meta-switches": + si.group = "Hidden-switches" + subapp.helpall() @switch(["-h", "--help"], overridable = True, group = "Meta-switches") def help(self): # @ReservedAssignment From 5251977148f3dd3489c7dcb6a3c78c66743c3436 Mon Sep 17 00:00:00 2001 From: Florian Friesdorf Date: Mon, 9 Jun 2014 12:00:24 +0200 Subject: [PATCH 2/2] cosmetical changes to --help-all --- plumbum/cli/application.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plumbum/cli/application.py b/plumbum/cli/application.py index 6b4c480f4..04e8e0ab3 100644 --- a/plumbum/cli/application.py +++ b/plumbum/cli/application.py @@ -389,11 +389,12 @@ def cleanup(self, retcode): :param retcode: the return code of ``main()`` """ + @switch(["--help-all"], overridable = True, group = "Meta-switches") def helpall(self): - """Prints the help messages of all subcommands and quits""" + """Print help messages of all subcommands and quit""" self.help() - print "\n" + print("") if self._subcommands: for name, subcls in sorted(self._subcommands.items()):