summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-06-13 17:47:41 -0700
committerSage Weil <sage@inktank.com>2013-06-13 17:47:41 -0700
commit71402a5daab97d6290294081f361ce20b1a133fa (patch)
treedbe52cd10cc05a97c2cc08c190ce97ddc1044e05
parentf6a864d0794cb67bd72c05b0a79289b84f382e41 (diff)
parent06f0b7248580235b9a2faccb8e593e429d176b55 (diff)
downloadceph-71402a5daab97d6290294081f361ce20b1a133fa.tar.gz
Merge pull request #363 from dmick/wip-cli-help
Reviewed-by: Sage Weil <sage@inktank.com>
-rwxr-xr-xsrc/ceph.in37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/ceph.in b/src/ceph.in
index 7d6c62a7303..8ec01c13cb6 100755
--- a/src/ceph.in
+++ b/src/ceph.in
@@ -837,7 +837,7 @@ def parse_cmdargs(args=None, target=''):
AP = argparse.ArgumentParser
# format our own help
- parser = AP(description='Frontend for ceph CLI', add_help=False)
+ parser = AP(description='Ceph administration tool', add_help=False)
parser.add_argument('--completion', action='store_true')
@@ -892,7 +892,7 @@ def parse_cmdargs(args=None, target=''):
return parser, parsed_args, extras
-def do_help(parser, help_all = False):
+def do_help(parser, args, help_all = False):
"""
Print basic parser help
If the cluster is available:
@@ -900,7 +900,7 @@ def do_help(parser, help_all = False):
if help_all, print help for daemon commands as well
"""
- def help_for_target(target):
+ def help_for_target(target, partial=None):
ret, outbuf, outs = json_command(target=target,
prefix='get_command_descriptions',
timeout=10)
@@ -909,12 +909,12 @@ def do_help(parser, help_all = False):
"couldn't get command descriptions for {0}: {1}".\
format(target, outs)
else:
- sys.stdout.write(format_help(parse_json_funcsigs(outbuf)))
+ sys.stdout.write(format_help(parse_json_funcsigs(outbuf), partial))
parser.print_help()
print '\n'
if (cluster_handle):
- help_for_target(target=('mon', ''))
+ help_for_target(target=('mon', ''), partial=' '.join(args))
if help_all and cluster_handle:
# try/except in case there are no daemons of that type
@@ -1006,7 +1006,7 @@ def wrap(s, width, indent):
raise StopIteration
-def format_help(cmddict):
+def format_help(cmddict, partial=None):
"""
Formats all the cmdsigs and helptexts from cmddict into a sorted-by-
cmdsig 2-column display, with each column wrapped and indented to
@@ -1018,7 +1018,10 @@ def format_help(cmddict):
if not cmd['helptext']:
continue
- siglines = [l for l in wrap(concise_sig(cmd['sig']), 40, 1)]
+ concise = concise_sig(cmd['sig'])
+ if partial and not concise.startswith(partial):
+ continue
+ siglines = [l for l in wrap(concise, 40, 1)]
helplines = [l for l in wrap(cmd['helptext'], 39, 1)]
# make lists the same length
@@ -1080,18 +1083,18 @@ def validate_command(parsed_args, sigdict, args):
pass
except ArgumentError as e:
# prefixes matched, but some other arg didn't;
- # this is interesting information
- print >> sys.stderr, '{0}: invalid command'.\
- format(' '.join(args))
- print >> sys.stderr, '{0}'.format(e)
- print >> sys.stderr, "did you mean {0}?\n\t{1}".\
- format(concise_sig(sig), helptext)
+ # this is interesting information if verbose
+ if verbose:
+ print >> sys.stderr, '{0}: invalid command'.\
+ format(' '.join(args))
+ print >> sys.stderr, '{0}'.format(e)
+ print >> sys.stderr, "did you mean {0}?\n\t{1}".\
+ format(concise_sig(sig), helptext)
pass
if not found:
- print >> sys.stderr, 'no valid command found'
- print >> sys.stderr, 'close matches:'
- for cmdsig in bestcmds:
+ print >> sys.stderr, 'no valid command found; 10 closest matches:'
+ for cmdsig in bestcmds[:10]:
for (cmdtag, cmd) in cmdsig.iteritems():
print >> sys.stderr, concise_sig(cmd['sig'])
return None
@@ -1463,7 +1466,7 @@ def main():
return 1
if parsed_args.help or parsed_args.help_all:
- return do_help(parser, parsed_args.help_all)
+ return do_help(parser, childargs, parsed_args.help_all)
# implement -w/--watch_*
# This is ugly, but Namespace() isn't quite rich enough.