diff options
author | Petr Viktorin <pviktori@redhat.com> | 2012-11-08 08:00:51 -0500 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2013-02-18 13:07:17 -0500 |
commit | 5ee2216f4973645f18f0ed8eac3c874d81e044ab (patch) | |
tree | 34784ae0c4236e81ecc539b37a6d9ff7872f31c4 | |
parent | 1e2437ece1f5d645ab5ab12628021798bb7b9e1a (diff) | |
download | freeipa-5ee2216f4973645f18f0ed8eac3c874d81e044ab.tar.gz freeipa-5ee2216f4973645f18f0ed8eac3c874d81e044ab.tar.xz freeipa-5ee2216f4973645f18f0ed8eac3c874d81e044ab.zip |
Store the OptionParser in the API, use it to print unified help messages
Make `ipa -h` and `ipa help` output the same message.
Since `ipa -h` output is generated by the OptionParser, we need to make
the parser available. Store it in `api.parser`.
Part of the effort for https://fedorahosted.org/freeipa/ticket/3060
-rw-r--r-- | ipalib/cli.py | 11 | ||||
-rw-r--r-- | ipalib/plugable.py | 1 |
2 files changed, 5 insertions, 7 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index 704a75ca3..a20c06e85 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -759,7 +759,7 @@ class help(frontend.Local): name = from_cli(key) mod_name = '%s.%s' % (self._PLUGIN_BASE_MODULE, name) if key is None: - make_ipa_parser().print_help(outfile) + self.api.parser.print_help(outfile) return if name == "topics": self.print_topics(outfile) @@ -771,7 +771,7 @@ class help(frontend.Local): if cmd.NO_CLI: raise HelpError(topic=name) writer(_('Purpose: %s') % unicode(_(cmd.doc)).strip()) - self.Backend.cli.build_parser(cmd).print_help() + self.Backend.cli.build_parser(cmd).print_help(outfile) elif mod_name in sys.modules: self.print_commands(name, outfile) elif name == "commands": @@ -795,10 +795,6 @@ class help(frontend.Local): writer(_('Usage: ipa [global-options] COMMAND [command-options]...')) writer() - writer(_('Built-in commands:')) - for c in self._builtins: - writer(' %s %s' % (to_cli(c.name).ljust(self._mtl), c.summary)) - writer() writer(_('Help topics:')) for t in topics: topic = self._topics[t] @@ -1029,8 +1025,9 @@ class cli(backend.Executioner): On incorrect invocation, prints out a help message and returns None """ if len(argv) == 0: + self.Command.help(outfile=sys.stderr) + print >>sys.stderr print >>sys.stderr, 'Error: Command not specified' - self.Command.help() exit(2) (key, argv) = (argv[0], argv[1:]) name = from_cli(key) diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 461497954..d2541e3b7 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -593,6 +593,7 @@ class API(DictProxy): if context is not None: overrides['context'] = context self.bootstrap(**overrides) + object.__setattr__(self, 'parser', parser) return (options, args) def load_plugins(self): |