]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph: make -h/--help show match when some args are supplied
authorSage Weil <sage@newdream.net>
Wed, 10 Nov 2021 16:53:35 +0000 (11:53 -0500)
committerSage Weil <sage@newdream.net>
Wed, 10 Nov 2021 21:30:47 +0000 (16:30 -0500)
Currently,

 # ceph orch ls -h
 ...
 orch ls [<service_type>] [<service_name>] [--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 <sage@newdream.net>
qa/workunits/cephtool/test.sh
src/ceph.in

index 9937fb1db8b6d6ed26edb6a11957460c356313f1..d63f88fc2e8f31315df696b24650902ea1456257 100755 (executable)
@@ -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.$$
index 3ebaed4af050373509c9be551a9b247c327025e3..d5023e6089ba6c70f6428f21fafa21089304e8af 100755 (executable)
@@ -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