diff options
Diffstat (limited to 'plac/plac_core.py')
-rw-r--r-- | plac/plac_core.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/plac/plac_core.py b/plac/plac_core.py index 0e12aff..7b0ad7f 100644 --- a/plac/plac_core.py +++ b/plac/plac_core.py @@ -104,7 +104,7 @@ def pconf(obj): cfg[name] = getattr(obj, name) return cfg -parser_registry = {} +_parser_registry = {} def parser_from(obj, **confparams): """ @@ -112,12 +112,12 @@ def parser_from(obj, **confparams): Returns an ArgumentParser. """ try: # the underlying parser has been generated already - return parser_registry[obj] + return _parser_registry[obj] except KeyError: # generate a new parser pass conf = pconf(obj).copy() conf.update(confparams) - parser_registry[obj] = parser = ArgumentParser(**conf) + _parser_registry[obj] = parser = ArgumentParser(**conf) parser.obj = obj parser.case_sensitive = confparams.get( 'case_sensitive', getattr(obj, 'case_sensitive', True)) @@ -163,10 +163,14 @@ class ArgumentParser(argparse.ArgumentParser): """ case_sensitive = True + def alias(self, arg): + "Can be overridden to preprocess command-line arguments" + return arg + def consume(self, args): """Call the underlying function with the args. Works also for command containers, by dispatching to the right subparser.""" - arglist = list(args) + arglist = map(self.alias, args) cmd = None if hasattr(self, 'subparsers'): subp, cmd = self._extract_subparser_cmd(arglist) @@ -223,7 +227,7 @@ class ArgumentParser(argparse.ArgumentParser): attribute to the parser. Also adds a .func reference to the object.""" self.func = obj self.argspec = getargspec(obj) - parser_registry[obj] = self + _parser_registry[obj] = self def populate_from(self, func): """ @@ -284,14 +288,6 @@ class ArgumentParser(argparse.ArgumentParser): self.error('No command %r' % name)) return miss(name) - def help_cmd(self, cmd): - "Return the help message for a subcommand" - p = self.subparsers._name_parser_map.get(cmd) - if p is None: - return _('Unknown command %s' % cmd) - else: - return p.format_help() - def print_actions(self): "Useful for debugging" print(self) |