@@ -108,65 +108,33 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
108108 sys .exit (ExitCodes .ARGUMENT_ERROR )
109109
110110 if parsed .command in ("set-custom-alias" , "remove-custom-alias" ):
111- # Ensure both --command and --alias are provided
112- # TODO: Can we use argparse for these
113- if len (args ) == 4 :
114- if args [0 ] != "--command" or args [2 ] != "--alias" :
115- print (
116- "Usage: linode-cli set-custom-alias --command "
117- "[COMMAND] --alias [ALIAS]" ,
118- file = sys .stderr ,
119- )
120- sys .exit (ExitCodes .ARGUMENT_ERROR )
121-
122- # Get the indexes for --command and --alias
123- try :
124- command_index = args .index ("--command" ) + 1
125- alias_index = args .index ("--alias" ) + 1
126- except ValueError :
111+ if not parsed .target_command or not parsed .alias :
127112 print (
128- "Both --command and --alias arguments are required ." ,
113+ "Both --target- command and --alias must be provided ." ,
129114 file = sys .stderr ,
130115 )
131116 sys .exit (ExitCodes .ARGUMENT_ERROR )
132117
133- if command_index >= len (args ) or alias_index >= len (args ):
134- print (
135- "Both --command and --alias arguments must have valid values." ,
136- file = sys .stderr ,
137- )
138- sys .exit (ExitCodes .ARGUMENT_ERROR )
118+ command = parsed .target_command
119+ alias = parsed .alias
139120
140- # Retrieve the command and alias from arguments
141- command = args [command_index ]
142- alias = args [alias_index ]
143-
144- # Check if the command is valid
145121 if command not in cli .ops :
146- print (
147- f"Error: '{ command } ' is not a valid command." , file = sys .stderr
148- )
122+ print (f"Error: '{ command } ' is not a valid command." , file = sys .stderr )
149123 sys .exit (ExitCodes .ARGUMENT_ERROR )
150124
151- # Set the alias if it does not already exist
152125 if parsed .command == "set-custom-alias" :
153126 if (alias , command ) not in cli .config .get_custom_aliases ().items ():
154127 cli .config .set_custom_alias (alias , command )
155128 print (f"Custom alias '{ alias } ' set for command '{ command } '" )
156129 else :
157- print (
158- f"Custom alias '{ alias } ' already set for command '{ command } '"
159- )
130+ print (f"Custom alias '{ alias } ' already set for command '{ command } '" )
160131
161- # Remove the alias if it already exists
162132 if parsed .command == "remove-custom-alias" :
163133 if (alias , command ) in cli .config .get_custom_aliases ().items ():
164134 cli .config .remove_custom_alias (alias , command )
165135 print (f"Custom alias '{ alias } ' removed for command '{ command } '" )
166136 else :
167- print (
168- f"Custom alias '{ alias } ' does not exist for command '{ command } '"
169- )
137+ print (f"Custom alias '{ alias } ' does not exist for command '{ command } '" )
170138
171139 sys .exit (ExitCodes .SUCCESS )
172140
0 commit comments