summaryrefslogtreecommitdiff
path: root/lib/python/milc.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/milc.py')
-rw-r--r--lib/python/milc.py14
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