summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/cli.py27
-rw-r--r--ipalib/public.py2
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