@@ -19,40 +19,28 @@ def add_sub_cmd(cmd: _SubParsersAction, subcmd, help) -> ArgumentParser:
19
19
return cmd .add_parser (subcmd , help = help )
20
20
21
21
22
- def add_sub_cmd_username (cmd : _SubParsersAction , subcmd , help ) -> ArgumentParser :
22
+ def add_sub_cmd_with_username_arg (cmd : _SubParsersAction , subcmd , help ) -> ArgumentParser :
23
23
"""Helper creates a new subcommand parser with a required username arg."""
24
- return add_username_arg (add_sub_cmd (cmd , subcmd , help = help ))
24
+ sub_cmd = add_sub_cmd (cmd , subcmd , help = help )
25
+ sub_cmd .add_argument ("username" , help = "A Compiler user account name, sans domain." )
26
+ return sub_cmd
25
27
26
28
27
- def add_username_arg (cmd : ArgumentParser ) -> ArgumentParser :
28
- cmd .add_argument ("username" , help = "A Compiler user account name, sans domain." )
29
- return cmd
30
-
31
-
32
- def main (argv = None ):
33
- argv = argv if argv is not None else sys .argv [1 :]
34
- parser = ArgumentParser (prog = "compiler-admin" )
35
-
36
- # https://stackoverflow.com/a/8521644/812183
37
- parser .add_argument (
38
- "-v" ,
39
- "--version" ,
40
- action = "version" ,
41
- version = f"%(prog)s { version } " ,
42
- )
43
-
44
- cmd_parsers = add_sub_cmd_parser (parser , dest = "command" , help = "The command to run" )
45
-
29
+ def setup_info_command (cmd_parsers : _SubParsersAction ):
46
30
info_cmd = add_sub_cmd (cmd_parsers , "info" , help = "Print configuration and debugging information." )
47
31
info_cmd .set_defaults (func = info )
48
32
49
- init_cmd = add_sub_cmd_username (
33
+
34
+ def setup_init_command (cmd_parsers : _SubParsersAction ):
35
+ init_cmd = add_sub_cmd_with_username_arg (
50
36
cmd_parsers , "init" , help = "Initialize a new admin project. This command should be run once before any others."
51
37
)
52
38
init_cmd .add_argument ("--gam" , action = "store_true" , help = "If provided, initialize a new GAM project." )
53
39
init_cmd .add_argument ("--gyb" , action = "store_true" , help = "If provided, initialize a new GYB project." )
54
40
init_cmd .set_defaults (func = init )
55
41
42
+
43
+ def setup_time_command (cmd_parsers : _SubParsersAction ):
56
44
time_cmd = add_sub_cmd (cmd_parsers , "time" , help = "Work with Compiler time entries" )
57
45
time_cmd .set_defaults (func = time )
58
46
time_subcmds = add_sub_cmd_parser (time_cmd , help = "The time command to run." )
@@ -66,35 +54,56 @@ def main(argv=None):
66
54
)
67
55
time_convert .add_argument ("--client" , default = None , help = "The name of the client to use in converted data." )
68
56
57
+
58
+ def setup_user_command (cmd_parsers : _SubParsersAction ):
69
59
user_cmd = add_sub_cmd (cmd_parsers , "user" , help = "Work with users in the Compiler org." )
70
60
user_cmd .set_defaults (func = user )
71
61
user_subcmds = add_sub_cmd_parser (user_cmd , help = "The user command to run." )
72
62
73
- user_create = add_sub_cmd_username (user_subcmds , "create" , help = "Create a new user in the Compiler domain." )
63
+ user_create = add_sub_cmd_with_username_arg (user_subcmds , "create" , help = "Create a new user in the Compiler domain." )
74
64
user_create .add_argument ("--notify" , help = "An email address to send the newly created account info." )
75
65
76
- user_convert = add_sub_cmd_username (user_subcmds , "convert" , help = "Convert a user account to a new type." )
66
+ user_convert = add_sub_cmd_with_username_arg (user_subcmds , "convert" , help = "Convert a user account to a new type." )
77
67
user_convert .add_argument ("account_type" , choices = ACCOUNT_TYPE_OU .keys (), help = "Target account type for this conversion." )
78
68
79
- user_delete = add_sub_cmd_username (user_subcmds , "delete" , help = "Delete a user account." )
69
+ user_delete = add_sub_cmd_with_username_arg (user_subcmds , "delete" , help = "Delete a user account." )
80
70
user_delete .add_argument ("--force" , action = "store_true" , default = False , help = "Don't ask for confirmation before deletion." )
81
71
82
- user_offboard = add_sub_cmd_username (user_subcmds , "offboard" , help = "Offboard a user account." )
72
+ user_offboard = add_sub_cmd_with_username_arg (user_subcmds , "offboard" , help = "Offboard a user account." )
83
73
user_offboard .add_argument ("--alias" , help = "Account to assign username as an alias." )
84
74
user_offboard .add_argument (
85
75
"--force" , action = "store_true" , default = False , help = "Don't ask for confirmation before offboarding."
86
76
)
87
77
88
- user_reset = add_sub_cmd_username (
78
+ user_reset = add_sub_cmd_with_username_arg (
89
79
user_subcmds , "reset-password" , help = "Reset a user's password to a randomly generated string."
90
80
)
91
81
user_reset .add_argument ("--notify" , help = "An email address to send the newly generated password." )
92
82
93
- add_sub_cmd_username (user_subcmds , "restore" , help = "Restore an email backup from a prior offboarding." )
83
+ add_sub_cmd_with_username_arg (user_subcmds , "restore" , help = "Restore an email backup from a prior offboarding." )
94
84
95
- user_signout = add_sub_cmd_username (user_subcmds , "signout" , help = "Signs a user out from all active sessions." )
85
+ user_signout = add_sub_cmd_with_username_arg (user_subcmds , "signout" , help = "Signs a user out from all active sessions." )
96
86
user_signout .add_argument ("--force" , action = "store_true" , default = False , help = "Don't ask for confirmation before signout." )
97
87
88
+
89
+ def main (argv = None ):
90
+ argv = argv if argv is not None else sys .argv [1 :]
91
+ parser = ArgumentParser (prog = "compiler-admin" )
92
+
93
+ # https://stackoverflow.com/a/8521644/812183
94
+ parser .add_argument (
95
+ "-v" ,
96
+ "--version" ,
97
+ action = "version" ,
98
+ version = f"%(prog)s { version } " ,
99
+ )
100
+
101
+ cmd_parsers = add_sub_cmd_parser (parser , dest = "command" , help = "The command to run" )
102
+ setup_info_command (cmd_parsers )
103
+ setup_init_command (cmd_parsers )
104
+ setup_time_command (cmd_parsers )
105
+ setup_user_command (cmd_parsers )
106
+
98
107
if len (argv ) == 0 :
99
108
argv = ["info" ]
100
109
0 commit comments