From: Sage Weil Date: Wed, 10 Nov 2021 16:53:35 +0000 (-0500) Subject: ceph: make -h/--help show match when some args are supplied X-Git-Tag: v17.1.0~372^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f988b2a833ea506de7e6709a03bbd3d6aff9b482;p=ceph-ci.git ceph: make -h/--help show match when some args are supplied Currently, # ceph orch ls -h ... orch ls [] [] [--export] [-- List services known to orchestrator format {plain|json|json-pretty|yaml}] [--refresh] # ceph orch ls osd -h ... nothing ... because the CLI is provided more arguments than the command prefix. Make -h drop right-hand args until we get at least one prefix match. This means we can have a partial command written with some args and add -h to get a usage for that command. Signed-off-by: Sage Weil --- diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh index 9937fb1db8b..d63f88fc2e8 100755 --- a/qa/workunits/cephtool/test.sh +++ b/qa/workunits/cephtool/test.sh @@ -1157,6 +1157,9 @@ function test_mon_mon() { # print help message ceph --help mon + # -h works even when some arguments are passed + ceph osd dump -h | grep 'osd dump' + ceph osd dump 123 -h | grep 'osd dump' # no mon add/remove ceph mon dump ceph mon getmap -o $TEMP_DIR/monmap.$$ diff --git a/src/ceph.in b/src/ceph.in index 3ebaed4af05..d5023e6089b 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -390,8 +390,15 @@ daemonperf {type.id | path} list|ls [stat-pats] [priority] def do_extended_help(parser, args, target, partial) -> int: def help_for_sigs(sigs, partial=None): try: - sys.stdout.write(format_help(parse_json_funcsigs(sigs, 'cli'), - partial=partial)) + while True: + out = format_help(parse_json_funcsigs(sigs, 'cli'), + partial=partial) + if not out and partial: + # shorten partial until we get at least one matching command prefix + partial = ' '.join(partial.split()[:-1]) + continue + sys.stdout.write(out) + break except BrokenPipeError: pass