Skip to content

Commit

Permalink
Make paasta without args compat with py3
Browse files Browse the repository at this point in the history
  • Loading branch information
solarkennedy committed Aug 8, 2017
1 parent bdd7b7f commit ee35f59
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions paasta_tools/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def get_argparser():
)

subparsers = parser.add_subparsers(help="[-h, --help] for subcommand help")
subparsers.required = True
# https://stackoverflow.com/questions/18282403/argparse-with-required-subcommands/18283730#18283730
subparsers.dest = 'command'

# Adding a separate help subparser allows us to respont to "help" without --help
help_parser = subparsers.add_parser('help', add_help=False)
help_parser.set_defaults(command=None)
Expand Down Expand Up @@ -115,11 +119,11 @@ def main(argv=None):
logging.basicConfig()
try:
args, parser = parse_args(argv)
if hasattr(args, 'command'):
return_code = args.command(args)
else:
if args.command is None:
parser.print_help()
return_code = 0
else:
return_code = args.command(args)
except KeyboardInterrupt:
return_code = 1
sys.exit(return_code)
Expand Down

0 comments on commit ee35f59

Please sign in to comment.