MILC: Add support for hidden subcommands (#7034)

* MILC: Add support for hidden subcommands

Subcommands with 'hidden=True' will not show up in the help output, but
will work as any other subcommands.

* Hide those hidden submodules, for real now

* Rebase on latest MILC
This commit is contained in:
Erovia 2019-11-21 21:52:00 +01:00 committed by skullydazed
parent f0790a722d
commit 7e7eb69edf
1 changed files with 8 additions and 6 deletions

View File

@ -595,23 +595,25 @@ class MILC(object):
return entrypoint_func
def add_subcommand(self, handler, description, name=None, **kwargs):
def add_subcommand(self, handler, description, name=None, hidden=False, **kwargs):
"""Register a subcommand.
If name is not provided we use `handler.__name__`.
"""
if self._inside_context_manager:
raise RuntimeError('You must run this before the with statement!')
if self._subparsers is None:
self.add_subparsers()
self.add_subparsers(metavar="")
if not name:
name = handler.__name__.replace("_", "-")
self.acquire_lock()
kwargs['help'] = description
if not hidden:
self._subparsers.metavar = "{%s,%s}" % (self._subparsers.metavar[1:-1], name) if self._subparsers.metavar else "{%s%s}" % (self._subparsers.metavar[1:-1], name)
kwargs['help'] = description
self.subcommands[name] = SubparserWrapper(self, name, self._subparsers.add_parser(name, **kwargs))
self.subcommands[name].set_defaults(entrypoint=handler)
@ -619,11 +621,11 @@ class MILC(object):
return handler
def subcommand(self, description, **kwargs):
def subcommand(self, description, hidden=False, **kwargs):
"""Decorator to register a subcommand.
"""
def subcommand_function(handler):
return self.add_subcommand(handler, description, **kwargs)
return self.add_subcommand(handler, description, hidden=hidden, **kwargs)
return subcommand_function