diff --git a/plumbum/cli/application.py b/plumbum/cli/application.py index 9d0677125..04e8e0ab3 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: @@ -384,6 +390,21 @@ def cleanup(self, retcode): :param retcode: the return code of ``main()`` """ + @switch(["--help-all"], overridable = True, group = "Meta-switches") + def helpall(self): + """Print help messages of all subcommands and quit""" + self.help() + print("") + + 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 """Prints this help message and quits"""