ValidAliasExpansionFunc returns a function that will check if the given string is a valid alias expansion. An expansion is valid if: - it is a shell expansion, - it is a non-shell expansion that corresponds to an existing command, extension, or alias.
(cmd *cobra.Command)
| 34 | // - it is a shell expansion, |
| 35 | // - it is a non-shell expansion that corresponds to an existing command, extension, or alias. |
| 36 | func ValidAliasExpansionFunc(cmd *cobra.Command) func(string) bool { |
| 37 | return func(expansion string) bool { |
| 38 | if strings.HasPrefix(expansion, "!") { |
| 39 | return true |
| 40 | } |
| 41 | |
| 42 | split, err := shlex.Split(expansion) |
| 43 | if err != nil || len(split) == 0 { |
| 44 | return false |
| 45 | } |
| 46 | |
| 47 | rootCmd := cmd.Root() |
| 48 | cmd, _, _ = rootCmd.Find(split) |
| 49 | return cmd != rootCmd |
| 50 | } |
| 51 | } |