1313from rich .table import Column , Table
1414
1515from linodecli import plugins
16+ from linodecli .exit_codes import ExitCodes
1617
1718from .arg_helpers import (
1819 bake_command ,
@@ -85,7 +86,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
8586 # print version info and exit - but only if no command was given
8687 print (f"linode-cli { VERSION } " )
8788 print (f"Built from spec version { cli .spec_version } " )
88- sys .exit (0 )
89+ sys .exit (ExitCodes . SUCCESS )
8990 else :
9091 # something else might want to parse version
9192 # find where it was originally, as it was removed from args
@@ -96,50 +97,50 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
9697 if parsed .command == "bake" :
9798 if parsed .action is None :
9899 print ("No spec provided, cannot bake" )
99- sys .exit (9 )
100+ sys .exit (ExitCodes . ARGUMENT_ERROR )
100101 bake_command (cli , parsed .action )
101- sys .exit (0 )
102+ sys .exit (ExitCodes . SUCCESS )
102103 elif cli .ops is None :
103104 # if not spec was found and we weren't baking, we're doomed
104- sys .exit (3 )
105+ sys .exit (ExitCodes . ARGUMENT_ERROR )
105106
106107 if parsed .command == "register-plugin" :
107108 if parsed .action is None :
108109 print ("register-plugin requires a module name!" )
109- sys .exit (9 )
110+ sys .exit (ExitCodes . ARGUMENT_ERROR )
110111 msg , code = register_plugin (parsed .action , cli .config , cli .ops )
111112 print (msg )
112113 sys .exit (code )
113114
114115 if parsed .command == "remove-plugin" :
115116 if parsed .action is None :
116117 print ("remove-plugin requires a plugin name to remove!" )
117- sys .exit (9 )
118+ sys .exit (ExitCodes . ARGUMENT_ERROR )
118119 msg , code = remove_plugin (parsed .action , cli .config )
119120 print (msg )
120121 sys .exit (code )
121122
122123 if parsed .command == "completion" :
123124 print (get_completions (cli .ops , parsed .help , parsed .action ))
124- sys .exit (0 )
125+ sys .exit (ExitCodes . SUCCESS )
125126
126127 # handle a help for the CLI
127128 if parsed .command is None or (parsed .command is None and parsed .help ):
128129 parser .print_help ()
129130 print_help_default ()
130- sys .exit (0 )
131+ sys .exit (ExitCodes . SUCCESS )
131132
132133 if parsed .command == "env-vars" :
133134 print_help_env_vars ()
134- sys .exit (0 )
135+ sys .exit (ExitCodes . SUCCESS )
135136
136137 if parsed .command == "commands" :
137138 print_help_commands (cli .ops )
138- sys .exit (0 )
139+ sys .exit (ExitCodes . SUCCESS )
139140
140141 if parsed .command == "plugins" :
141142 print_help_plugins (cli .config )
142- sys .exit (0 )
143+ sys .exit (ExitCodes . SUCCESS )
143144
144145 # configure
145146 if parsed .command == "configure" :
@@ -151,7 +152,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
151152 )
152153 else :
153154 cli .configure ()
154- sys .exit (0 )
155+ sys .exit (ExitCodes . SUCCESS )
155156
156157 # block of commands for user-focused operations
157158 if parsed .command == "set-user" :
@@ -163,7 +164,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
163164 )
164165 else :
165166 cli .config .set_default_user (parsed .action )
166- sys .exit (0 )
167+ sys .exit (ExitCodes . SUCCESS )
167168
168169 if parsed .command == "show-users" :
169170 if parsed .help :
@@ -177,7 +178,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
177178 )
178179 else :
179180 cli .config .print_users ()
180- sys .exit (0 )
181+ sys .exit (ExitCodes . SUCCESS )
181182
182183 if parsed .command == "remove-user" :
183184 if parsed .help or not parsed .action :
@@ -190,7 +191,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
190191 )
191192 else :
192193 cli .config .remove_user (parsed .action )
193- sys .exit (0 )
194+ sys .exit (ExitCodes . SUCCESS )
194195
195196 # check for plugin invocation
196197 if parsed .command not in cli .ops and parsed .command in plugins .available (
@@ -202,7 +203,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
202203 plugin_args = argv [1 :] # don't include the program name
203204 plugin_args .remove (parsed .command ) # don't include the plugin name
204205 plugins .invoke (parsed .command , plugin_args , context )
205- sys .exit (0 )
206+ sys .exit (ExitCodes . SUCCESS )
206207
207208 # unknown commands
208209 if (
@@ -211,7 +212,7 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
211212 and parsed .command not in HELP_TOPICS
212213 ):
213214 print (f"Unrecognized command { parsed .command } " )
214- sys .exit (1 )
215+ sys .exit (ExitCodes . UNRECOGNIZED_COMMAND )
215216
216217 # handle a help for a command - either --help or no action triggers this
217218 if (
@@ -236,10 +237,10 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
236237 table .add_row (* row )
237238
238239 rprint (table )
239- sys .exit (0 )
240+ sys .exit (ExitCodes . SUCCESS )
240241
241242 if parsed .command is not None and parsed .action is not None :
242243 if parsed .help :
243244 print_help_action (cli , parsed .command , parsed .action )
244- sys .exit (0 )
245+ sys .exit (ExitCodes . SUCCESS )
245246 cli .handle_command (parsed .command , parsed .action , args )
0 commit comments