| 429 | |
| 430 | |
| 431 | class InternalAliasSubCommand(BaseInternalAliasCommand): |
| 432 | def __init__( |
| 433 | self, |
| 434 | alias_name, |
| 435 | alias_value, |
| 436 | command_object, |
| 437 | global_args_parser, |
| 438 | session, |
| 439 | proxied_sub_command=None, |
| 440 | ): |
| 441 | super(InternalAliasSubCommand, self).__init__( |
| 442 | alias_name, alias_value, session |
| 443 | ) |
| 444 | self._command_object = command_object |
| 445 | self._global_args_parser = global_args_parser |
| 446 | self._proxied_sub_command = proxied_sub_command |
| 447 | |
| 448 | def _process_global_args(self, arg_parser, alias_args, parsed_globals): |
| 449 | globally_parseable_args = [parsed_globals.command] + alias_args |
| 450 | alias_globals, remaining = arg_parser.parse_known_args( |
| 451 | globally_parseable_args |
| 452 | ) |
| 453 | self._update_parsed_globals(arg_parser, alias_globals, parsed_globals) |
| 454 | return remaining |
| 455 | |
| 456 | def create_help_command(self): |
| 457 | # In the future we could create a custom help command |
| 458 | # that documents that this is an alias with more info. |
| 459 | return self._command_object.create_help_command() |
| 460 | |
| 461 | def __call__(self, args, parsed_globals): |
| 462 | # args - Args explicitly provided by the user when |
| 463 | # invoking this command. |
| 464 | # parsed_globals - Global args explicitly provided by the user |
| 465 | # that we've already parsed. |
| 466 | # alias_args - Any args (including the command name) that are |
| 467 | # embedded as part of the alias value (i.e defined in the alias file) |
| 468 | alias_args = self._get_alias_args() |
| 469 | cmd_specific_args = self._process_global_args( |
| 470 | self._global_args_parser, alias_args, parsed_globals |
| 471 | ) |
| 472 | cmd_specific_args.extend(args) |
| 473 | if self._proxied_sub_command is not None: |
| 474 | # If we overwrote an existing command, we just delegate to that |
| 475 | # command we proxied to. We know that when this happens, the |
| 476 | # first argument will match the command associated with this |
| 477 | # command so we remove that value before delegating to the |
| 478 | # proxied command. |
| 479 | cmd_specific_args = cmd_specific_args[1:] |
| 480 | LOG.debug( |
| 481 | "Delegating to proxy sub-command with new alias args: %s", |
| 482 | alias_args, |
| 483 | ) |
| 484 | return self._proxied_sub_command(cmd_specific_args, parsed_globals) |
| 485 | else: |
| 486 | return self._command_object(cmd_specific_args, parsed_globals) |
no outgoing calls