Skip to content

Commit

Permalink
feat: better output and exit code from incomplete subcommands
Browse files Browse the repository at this point in the history
  • Loading branch information
infinitewarp committed Jul 9, 2024
1 parent 02f6876 commit 02256bb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion qpc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def __init__(self, name="cli", usage=None, shortdesc=None, description=None):
default=0,
help=_(messages.VERBOSITY_HELP),
)
# Note: We deliberately omit "required=True" from this specific subparser.
# This means a bare "qpc" call with no arguments will still be handled by our
# code, not argparse's input validation, and result in us calling print_help.
self.subparsers = self.parser.add_subparsers(dest="subcommand")
self.name = name
self.args = None
Expand Down Expand Up @@ -186,7 +189,9 @@ def __init__(self, name="cli", usage=None, shortdesc=None, description=None):

def _add_subcommand(self, subcommand, actions):
subcommand_parser = self.subparsers.add_parser(subcommand)
action_subparsers = subcommand_parser.add_subparsers(dest="action")
action_subparsers = subcommand_parser.add_subparsers(
dest="action", required=True
)
self.subcommands[subcommand] = {}
for action in actions:
action_inst = action(action_subparsers)
Expand Down

0 comments on commit 02256bb

Please sign in to comment.