|
|
|
@@ -501,12 +501,12 @@ class MILC(object):
|
|
|
|
|
|
|
|
|
|
if argument not in self.arg_only:
|
|
|
|
|
# Find the argument's section
|
|
|
|
|
argument_found = True
|
|
|
|
|
for group in self.default_arguments:
|
|
|
|
|
if argument in self.default_arguments[group]:
|
|
|
|
|
argument_found = True
|
|
|
|
|
section = group
|
|
|
|
|
break
|
|
|
|
|
if self._entrypoint.__name__ in self.default_arguments and argument in self.default_arguments[self._entrypoint.__name__]:
|
|
|
|
|
argument_found = True
|
|
|
|
|
section = self._entrypoint.__name__
|
|
|
|
|
if argument in self.default_arguments['general']:
|
|
|
|
|
argument_found = True
|
|
|
|
|
section = 'general'
|
|
|
|
|
|
|
|
|
|
if not argument_found:
|
|
|
|
|
raise RuntimeError('Could not find argument in `self.default_arguments`. This should be impossible!')
|
|
|
|
@@ -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
|
|
|
|
|
|
|
|
|
|