|
46 | 46 |
|
47 | 47 | # if any of these arguments are given, we don't need to prompt for configuration |
48 | 48 | skip_config = ( |
49 | | - any( |
50 | | - c in argv |
51 | | - for c in ["--skip-config", "--help", "--version", "completion"] |
52 | | - ) |
| 49 | + any(c in argv for c in ["--skip-config", "--version", "completion"]) |
53 | 50 | or TEST_MODE |
54 | 51 | ) |
55 | 52 |
|
@@ -110,6 +107,43 @@ def main(): # pylint: disable=too-many-branches,too-many-statements |
110 | 107 | # if not spec was found and we weren't baking, we're doomed |
111 | 108 | sys.exit(ExitCodes.ARGUMENT_ERROR) |
112 | 109 |
|
| 110 | + if parsed.command in ("set-custom-alias", "remove-custom-alias"): |
| 111 | + if not parsed.target_command or not parsed.alias: |
| 112 | + print( |
| 113 | + "Both --target-command and --alias must be provided.", |
| 114 | + file=sys.stderr, |
| 115 | + ) |
| 116 | + sys.exit(ExitCodes.ARGUMENT_ERROR) |
| 117 | + |
| 118 | + command = parsed.target_command |
| 119 | + alias = parsed.alias |
| 120 | + |
| 121 | + if command not in cli.ops: |
| 122 | + print( |
| 123 | + f"Error: '{command}' is not a valid command.", file=sys.stderr |
| 124 | + ) |
| 125 | + sys.exit(ExitCodes.ARGUMENT_ERROR) |
| 126 | + |
| 127 | + if parsed.command == "set-custom-alias": |
| 128 | + if (alias, command) not in cli.config.get_custom_aliases().items(): |
| 129 | + cli.config.set_custom_alias(alias, command) |
| 130 | + print(f"Custom alias '{alias}' set for command '{command}'") |
| 131 | + else: |
| 132 | + print( |
| 133 | + f"Custom alias '{alias}' already set for command '{command}'" |
| 134 | + ) |
| 135 | + |
| 136 | + if parsed.command == "remove-custom-alias": |
| 137 | + if (alias, command) in cli.config.get_custom_aliases().items(): |
| 138 | + cli.config.remove_custom_alias(alias, command) |
| 139 | + print(f"Custom alias '{alias}' removed for command '{command}'") |
| 140 | + else: |
| 141 | + print( |
| 142 | + f"Custom alias '{alias}' does not exist for command '{command}'" |
| 143 | + ) |
| 144 | + |
| 145 | + sys.exit(ExitCodes.SUCCESS) |
| 146 | + |
113 | 147 | if parsed.command == "register-plugin": |
114 | 148 | if parsed.action is None: |
115 | 149 | print("register-plugin requires a module name!", file=sys.stderr) |
@@ -213,28 +247,36 @@ def main(): # pylint: disable=too-many-branches,too-many-statements |
213 | 247 | plugin_args.remove(parsed.command) # don't include the plugin name |
214 | 248 | plugins.invoke(parsed.command, plugin_args, context) |
215 | 249 | sys.exit(ExitCodes.SUCCESS) |
216 | | - |
217 | 250 | # unknown commands |
218 | 251 | if ( |
219 | 252 | parsed.command not in cli.ops |
220 | 253 | and parsed.command not in plugins.available(cli.config) |
221 | 254 | and parsed.command not in HELP_TOPICS |
| 255 | + and parsed.command not in cli.config.get_custom_aliases().keys() |
222 | 256 | ): |
223 | 257 | print(f"Unrecognized command {parsed.command}", file=sys.stderr) |
224 | 258 | sys.exit(ExitCodes.UNRECOGNIZED_COMMAND) |
225 | 259 |
|
226 | 260 | # handle a help for a command - either --help or no action triggers this |
227 | | - if ( |
228 | | - parsed.command is not None |
229 | | - and parsed.action is None |
230 | | - and parsed.command in cli.ops |
231 | | - ): |
232 | | - print_help_command_actions(cli.ops, parsed.command) |
233 | | - sys.exit(ExitCodes.SUCCESS) |
| 261 | + if parsed.command is not None and parsed.action is None: |
| 262 | + if parsed.command in cli.ops: |
| 263 | + print_help_command_actions(cli.ops, parsed.command) |
| 264 | + sys.exit(ExitCodes.SUCCESS) |
| 265 | + if parsed.command in cli.config.get_custom_aliases().keys(): |
| 266 | + print_help_command_actions( |
| 267 | + cli.ops, cli.config.get_custom_aliases()[parsed.command] |
| 268 | + ) |
234 | 269 |
|
235 | 270 | if parsed.command is not None and parsed.action is not None: |
236 | 271 | if parsed.help: |
237 | | - print_help_action(cli, parsed.command, parsed.action) |
| 272 | + if parsed.command in cli.config.get_custom_aliases().keys(): |
| 273 | + print_help_action( |
| 274 | + cli, |
| 275 | + cli.config.get_custom_aliases()[parsed.command], |
| 276 | + parsed.action, |
| 277 | + ) |
| 278 | + else: |
| 279 | + print_help_action(cli, parsed.command, parsed.action) |
238 | 280 | sys.exit(ExitCodes.SUCCESS) |
239 | 281 |
|
240 | 282 | cli.handle_command(parsed.command, parsed.action, args) |
0 commit comments