resolveAliasTarget returns the command a user-defined alias expands to, or command unchanged when it is not an alias or the target cannot be resolved. Shell aliases have no target command and are always returned unchanged.
(command *cobra.Command)
| 356 | // command unchanged when it is not an alias or the target cannot be resolved. |
| 357 | // Shell aliases have no target command and are always returned unchanged. |
| 358 | func resolveAliasTarget(command *cobra.Command) *cobra.Command { |
| 359 | expansion, ok := command.Annotations[aliasExpansionAnnotation] |
| 360 | if !ok { |
| 361 | return command |
| 362 | } |
| 363 | args, err := shlex.Split(expansion) |
| 364 | if err != nil || len(args) == 0 { |
| 365 | return command |
| 366 | } |
| 367 | target, _, err := command.Root().Find(args) |
| 368 | if err != nil || target == nil { |
| 369 | return command |
| 370 | } |
| 371 | return target |
| 372 | } |