summaryrefslogtreecommitdiffstats
path: root/ipalib/cli.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-09 01:41:15 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-09 01:41:15 +0000
commit21a0bab79ec9cddb98d6d3ab478ea48674eeda06 (patch)
tree3fb30a852b443e28c0b9f2cca4006685d70d6993 /ipalib/cli.py
parent13f030d91e378064291d2065b547047bb3f175e8 (diff)
downloadfreeipa.git-21a0bab79ec9cddb98d6d3ab478ea48674eeda06.tar.gz
freeipa.git-21a0bab79ec9cddb98d6d3ab478ea48674eeda06.tar.xz
freeipa.git-21a0bab79ec9cddb98d6d3ab478ea48674eeda06.zip
272: Add a quick positional arg experiment
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r--ipalib/cli.py27
1 files changed, 26 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.