aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Norris <computersforpeace@gmail.com>2015-10-16 16:39:03 -0700
committerStephen Finucane <stephen.finucane@intel.com>2015-10-20 01:52:24 +0100
commit300e190370ccda0c78284f31b1ec077d2e94e247 (patch)
tree435f6b3547aa6dbad772bb067d4d66ecdab1b27a
parent252844f51c9f84fe2858832f6b93bd9d41017392 (diff)
downloadpatchwork-300e190370ccda0c78284f31b1ec077d2e94e247.tar
patchwork-300e190370ccda0c78284f31b1ec077d2e94e247.tar.gz
pwclient: use argparse's error() function for bad input
This reduces the boilerplate we need and provides a more consistent help output. e.g.: $ pwclient update -s FOO -c 1337 314159 1234567 usage: pwclient update [--help] [-h HASH] [-p PROJECT] [-c COMMIT-REF] [-s STATE] [-a {yes,no}] [ID [ID ...]] pwclient update: error: Declining update with COMMIT-REF on multiple IDs Signed-off-by: Brian Norris <computersforpeace@gmail.com> Reviewed-by: Mike Frysinger <vapier@chromium.org> Reviewed-by: Stephen Finucane <stephen.finucane@intel.com>
-rwxr-xr-xpatchwork/bin/pwclient20
1 files changed, 5 insertions, 15 deletions
diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
index 9d34d54..76dd97b 100755
--- a/patchwork/bin/pwclient
+++ b/patchwork/bin/pwclient
@@ -493,10 +493,8 @@ def main():
if args.get('hash') and len(args.get('id')):
# mimic mutual exclusive group
- sys.stderr.write("Error: [-h HASH] and [ID [ID ...]] " +
- "are mutually exlusive\n")
- locals()[action + '_parser'].print_help()
- sys.exit(1)
+ locals()[action + '_parser'].error(
+ "[-h HASH] and [ID [ID ...]] are mutually exlusive")
# set defaults
filt = Filter()
@@ -515,11 +513,7 @@ def main():
if args.get('c'):
# update multiple IDs with a single commit-hash does not make sense
if action == 'update' and patch_ids and len(patch_ids) > 1:
- sys.stderr.write(
- "Declining update with COMMIT-REF on multiple IDs\n"
- )
- update_parser.print_help()
- sys.exit(1)
+ update_parser.error("Declining update with COMMIT-REF on multiple IDs")
commit_str = args.get('c')
if state_str is None and archived_str is None and action == 'update':
@@ -529,9 +523,7 @@ def main():
try:
filt.add("max_count", args.get('n'))
except:
- sys.stderr.write("Invalid maximum count '%s'\n" % args.get('n'))
- action_parser.print_help()
- sys.exit(1)
+ action_parser.error("Invalid maximum count '%s'" % args.get('n'))
do_signoff = args.get('signoff')
@@ -572,9 +564,7 @@ def main():
try:
project_str = config.get('options', 'default')
except:
- sys.stderr.write("No default project configured in ~/.pwclientrc\n")
- action_parser.print_help()
- sys.exit(1)
+ action_parser.error("No default project configured in ~/.pwclientrc")
if not config.has_section(project_str):
sys.stderr.write('No section for project %s in ~/.pwclientrc\n' % project_str)