Skip to content

Commit 300e190

Browse files
computersforpeacestephenfin
authored andcommitted
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 <[email protected]> Reviewed-by: Mike Frysinger <[email protected]> Reviewed-by: Stephen Finucane <[email protected]>
1 parent 252844f commit 300e190

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

patchwork/bin/pwclient

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,8 @@ def main():
493493

494494
if args.get('hash') and len(args.get('id')):
495495
# mimic mutual exclusive group
496-
sys.stderr.write("Error: [-h HASH] and [ID [ID ...]] " +
497-
"are mutually exlusive\n")
498-
locals()[action + '_parser'].print_help()
499-
sys.exit(1)
496+
locals()[action + '_parser'].error(
497+
"[-h HASH] and [ID [ID ...]] are mutually exlusive")
500498

501499
# set defaults
502500
filt = Filter()
@@ -515,11 +513,7 @@ def main():
515513
if args.get('c'):
516514
# update multiple IDs with a single commit-hash does not make sense
517515
if action == 'update' and patch_ids and len(patch_ids) > 1:
518-
sys.stderr.write(
519-
"Declining update with COMMIT-REF on multiple IDs\n"
520-
)
521-
update_parser.print_help()
522-
sys.exit(1)
516+
update_parser.error("Declining update with COMMIT-REF on multiple IDs")
523517
commit_str = args.get('c')
524518

525519
if state_str is None and archived_str is None and action == 'update':
@@ -529,9 +523,7 @@ def main():
529523
try:
530524
filt.add("max_count", args.get('n'))
531525
except:
532-
sys.stderr.write("Invalid maximum count '%s'\n" % args.get('n'))
533-
action_parser.print_help()
534-
sys.exit(1)
526+
action_parser.error("Invalid maximum count '%s'" % args.get('n'))
535527

536528
do_signoff = args.get('signoff')
537529

@@ -572,9 +564,7 @@ def main():
572564
try:
573565
project_str = config.get('options', 'default')
574566
except:
575-
sys.stderr.write("No default project configured in ~/.pwclientrc\n")
576-
action_parser.print_help()
577-
sys.exit(1)
567+
action_parser.error("No default project configured in ~/.pwclientrc")
578568

579569
if not config.has_section(project_str):
580570
sys.stderr.write('No section for project %s in ~/.pwclientrc\n' % project_str)

0 commit comments

Comments
 (0)