diff options
author | Dan Mick <dan.mick@inktank.com> | 2013-09-26 22:24:37 -0700 |
---|---|---|
committer | Dan Mick <dan.mick@inktank.com> | 2013-09-30 21:09:16 -0700 |
commit | 3452aadd81dae627f4321aa40db9d6c14466ef16 (patch) | |
tree | 87be7eb60fcb22784b57a94694a674939fddee1e | |
parent | fac4a897f948c51e22b075b42e5cbe8a259235bc (diff) | |
download | ceph-3452aadd81dae627f4321aa40db9d6c14466ef16.tar.gz |
ceph_argparse.py: clean up error reporting when required param missing
Treat "need 1, got 0" as a special case, and change the message to
"missing required parameter <x>". Also, when failing for that reason,
print the command concise description and its helptext.
Fixes: #6384
Signed-off-by: Dan Mick <dan.mick@inktank.com>
-rw-r--r-- | src/pybind/ceph_argparse.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/pybind/ceph_argparse.py b/src/pybind/ceph_argparse.py index 7ec7b8b2f0c..1f6e90b6c1d 100644 --- a/src/pybind/ceph_argparse.py +++ b/src/pybind/ceph_argparse.py @@ -843,6 +843,11 @@ def validate(args, signature, partial=False): # wanted n, got too few if partial: return d + # special-case the "0 expected 1" case + if desc.numseen == 0 and desc.n == 1: + raise ArgumentNumber( + 'missing required parameter {0}'.format(desc) + ) raise ArgumentNumber( 'saw {0} of {1}, expected {2}'.\ format(desc.numseen, desc, desc.n) @@ -951,6 +956,7 @@ def validate_command(sigdict, args, verbose=False): # Stop now, because we have the right command but # some other input is invalid print >> sys.stderr, "Invalid command: ", str(e) + print >> sys.stderr, concise_sig(sig), ': ', cmd['help'] return {} if found: break |