Skip to content

Commit 103ed7e

Browse files
committed
refactor(main): helper to add subparser
1 parent b589699 commit 103ed7e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

compiler_admin/main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
from compiler_admin.commands.user.convert import ACCOUNT_TYPE_OU
1010

1111

12+
def add_sub_cmd_parser(parser: ArgumentParser, dest="subcommand", help=None):
13+
"""Helper adds a subparser for the given dest."""
14+
return parser.add_subparsers(dest=dest, help=help)
15+
16+
1217
def add_sub_cmd(cmd: _SubParsersAction, subcmd, help) -> ArgumentParser:
1318
"""Helper creates a new subcommand parser."""
1419
return cmd.add_parser(subcmd, help=help)
@@ -36,7 +41,7 @@ def main(argv=None):
3641
version=f"%(prog)s {version}",
3742
)
3843

39-
cmd_parsers = parser.add_subparsers(dest="command", help="The command to run")
44+
cmd_parsers = add_sub_cmd_parser(parser, dest="command", help="The command to run")
4045

4146
info_cmd = add_sub_cmd(cmd_parsers, "info", help="Print configuration and debugging information.")
4247
info_cmd.set_defaults(func=info)
@@ -50,7 +55,7 @@ def main(argv=None):
5055

5156
time_cmd = add_sub_cmd(cmd_parsers, "time", help="Work with Compiler time entries")
5257
time_cmd.set_defaults(func=time)
53-
time_subcmds = time_cmd.add_subparsers("subcommand", help="The time command to run.")
58+
time_subcmds = add_sub_cmd_parser(time_cmd, help="The time command to run.")
5459

5560
time_convert = add_sub_cmd(time_subcmds, "convert", help="Convert a time report from one format into another.")
5661
time_convert.add_argument(
@@ -63,7 +68,7 @@ def main(argv=None):
6368

6469
user_cmd = add_sub_cmd(cmd_parsers, "user", help="Work with users in the Compiler org.")
6570
user_cmd.set_defaults(func=user)
66-
user_subcmds = user_cmd.add_subparsers(dest="subcommand", help="The user command to run.")
71+
user_subcmds = add_sub_cmd_parser(user_cmd, help="The user command to run.")
6772

6873
user_create = add_sub_cmd_username(user_subcmds, "create", help="Create a new user in the Compiler domain.")
6974
user_create.add_argument("--notify", help="An email address to send the newly created account info.")

0 commit comments

Comments
 (0)