From: David Zafman Date: Tue, 17 Mar 2015 03:34:10 +0000 (-0700) Subject: Improve "ceph_argparse.py: add stderr note if nonrequired param is invalid" X-Git-Tag: v0.94~24^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a3dfeec07a4e87f0be1025d6174c3f1308f53481;p=ceph.git Improve "ceph_argparse.py: add stderr note if nonrequired param is invalid" When processing arguments stash an exception which is seen when looking for another argument type. If we have extra args at the end, output information about the exception which probably caused the problem. Fixes: #11093 Original fix: 71ff794eca7dd57a0b0473530f685069ac9987f0 Signed-off-by: David Zafman --- diff --git a/src/pybind/ceph_argparse.py b/src/pybind/ceph_argparse.py index 3d202da5bcde..12f0b708a110 100644 --- a/src/pybind/ceph_argparse.py +++ b/src/pybind/ceph_argparse.py @@ -868,7 +868,7 @@ def validate(args, signature, partial=False): if not desc.req: # if not required, just push back; it might match # the next arg - print >> sys.stderr, myarg, 'not valid: ', str(e) + save_exception = [ myarg, e ] myargs.insert(0, myarg) break else: @@ -880,12 +880,16 @@ def validate(args, signature, partial=False): # Whew, valid arg acquired. Store in dict matchcnt += 1 store_arg(desc, d) + # Clear prior exception + save_exception = None # Done with entire list of argdescs if matchcnt < reqsiglen: raise ArgumentTooFew("not enough arguments given") if myargs and not partial: + if save_exception: + print >> sys.stderr, save_exception[0], 'not valid: ', str(save_exception[1]) raise ArgumentError("unused arguments: " + str(myargs)) # Finally, success