]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/ceph_argparse.py: show usage on fully matched cmd 21973/head
authorKefu Chai <kchai@redhat.com>
Mon, 14 May 2018 10:27:22 +0000 (18:27 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 14 May 2018 12:04:26 +0000 (20:04 +0800)
before this change,

ceph config show
no valid command found; 2 closest matches:
config show {}
config show-with-defaults
Error EINVAL: invalid command

after this change

ceph config show
Invalid command: missing required parameter who(<string>)
config show <who> {<key>} :  Show running configuration
Error EINVAL: invalid command

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/ceph_argparse.py

index 8bac68cc57ce8004259086a4148b429efa36e180..fe15bf074c75e554ef494b7cdf512bef467772d9 100644 (file)
@@ -12,6 +12,7 @@ LGPL2.1.  See file COPYING.
 from __future__ import print_function
 import copy
 import errno
+import math
 import json
 import os
 import pprint
@@ -1031,18 +1032,20 @@ def validate_command(sigdict, args, verbose=False):
         for cmdtag, cmd in sigdict.items():
             sig = cmd['sig']
             matched = matchnum(args, sig, partial=True)
+            if (matched >= math.floor(best_match_cnt) and
+                matched == matchnum(args, sig, partial=False)):
+                # prefer those fully matched over partial patch
+                matched += 0.5
+            if matched < best_match_cnt:
+                continue
+            if verbose:
+                print("better match: {0} > {1}: {2}:{3} ".format(
+                    matched, best_match_cnt, cmdtag, concise_sig(sig)
+                ), file=sys.stderr)
             if matched > best_match_cnt:
-                if verbose:
-                    print("better match: {0} > {1}: {2}:{3} ".format(
-                        matched, best_match_cnt, cmdtag, concise_sig(sig)
-                    ), file=sys.stderr)
                 best_match_cnt = matched
                 bestcmds = [{cmdtag: cmd}]
-            elif matched == best_match_cnt:
-                if verbose:
-                    print("equal match: {0} > {1}: {2}:{3} ".format(
-                        matched, best_match_cnt, cmdtag, concise_sig(sig)
-                    ), file=sys.stderr)
+            else:
                 bestcmds.append({cmdtag: cmd})
 
         # Sort bestcmds by number of args so we can try shortest first