diff options
author | Erovia <Erovia@users.noreply.github.com> | 2019-11-21 21:52:00 +0100 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-11-21 12:52:00 -0800 |
commit | 7e7eb69edffca39b51e8fdcd5eaa76262e16eaf4 (patch) | |
tree | 68413d22bb38d8ed2534eb1f705d6e19ebab68e6 | |
parent | f0790a722d5a586e3621487b554fd217839c24c0 (diff) |
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
-rw-r--r-- | lib/python/milc.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/python/milc.py b/lib/python/milc.py index e8599eff3f..4392c8376a 100644 --- a/lib/python/milc.py +++ b/lib/python/milc.py @@ -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 |