diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-09 01:41:15 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-09 01:41:15 +0000 |
commit | 21a0bab79ec9cddb98d6d3ab478ea48674eeda06 (patch) | |
tree | 3fb30a852b443e28c0b9f2cca4006685d70d6993 | |
parent | 13f030d91e378064291d2065b547047bb3f175e8 (diff) | |
download | freeipa.git-21a0bab79ec9cddb98d6d3ab478ea48674eeda06.tar.gz freeipa.git-21a0bab79ec9cddb98d6d3ab478ea48674eeda06.tar.xz freeipa.git-21a0bab79ec9cddb98d6d3ab478ea48674eeda06.zip |
272: Add a quick positional arg experiment
-rw-r--r-- | ipalib/cli.py | 27 | ||||
-rw-r--r-- | ipalib/public.py | 2 |
2 files changed, 28 insertions, 1 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index 048f49ff..b2251432 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -28,6 +28,7 @@ import optparse import public import errors import plugable +import ipa_types def to_cli(name): @@ -49,6 +50,14 @@ def from_cli(cli_name): class help(public.Application): 'Display help on a command.' + + takes_args = ( + public.Option('command', 'The doc', ipa_types.Unicode(), + required=True, + multivalue=True, + ), + ) + def __call__(self, key): key = str(key) if key not in self.application: @@ -222,7 +231,7 @@ class CLI(object): def build_parser(self, cmd): parser = optparse.OptionParser( - usage='Usage: %%prog %s' % to_cli(cmd.name), + usage=self.get_usage(cmd), ) for option in cmd.Option(): parser.add_option('--%s' % to_cli(option.name), @@ -231,6 +240,22 @@ class CLI(object): ) return parser + def get_usage(self, cmd): + return ' '.join(self.get_usage_iter(cmd)) + + def get_usage_iter(self, cmd): + yield 'Usage: %%prog %s' % to_cli(cmd.name) + for arg in cmd.takes_args: + name = to_cli(arg.name).upper() + if arg.multivalue: + name = '%s...' % name + if arg.required: + yield name + else: + yield '[%s]' % name + + + def __get_mcl(self): """ Returns the Max Command Length. diff --git a/ipalib/public.py b/ipalib/public.py index a5385a92..90b3b88a 100644 --- a/ipalib/public.py +++ b/ipalib/public.py @@ -208,9 +208,11 @@ class Command(plugable.Plugin): '__call__', 'smart_option_order', 'Option', + 'takes_args', )) __Option = None options = tuple() + takes_args = tuple() def get_options(self): return self.options |