From ee35f597dcd2e44c23705e442fbc9dbc6a468858 Mon Sep 17 00:00:00 2001 From: Kyle Anderson Date: Mon, 7 Aug 2017 17:53:24 -0700 Subject: [PATCH] Make paasta without args compat with py3 --- paasta_tools/cli/cli.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/paasta_tools/cli/cli.py b/paasta_tools/cli/cli.py index 79e1d27039..7fa8a99b42 100755 --- a/paasta_tools/cli/cli.py +++ b/paasta_tools/cli/cli.py @@ -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) @@ -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)