Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help all, print help for a command and all its subcommands #125

Merged
merged 2 commits into from
Jun 9, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions plumbum/cli/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

class ShowHelp(SwitchError):
pass
class ShowHelpAll(SwitchError):
pass
class ShowVersion(SwitchError):
pass

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"""
Expand Down