MCPcopy
hub / github.com/cli/cli / ValidAliasExpansionFunc

Function ValidAliasExpansionFunc

pkg/cmd/alias/shared/validations.go:36–51  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

34// - it is a shell expansion,
35// - it is a non-shell expansion that corresponds to an existing command, extension, or alias.
36func 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}

Callers 6

NewCmdRootFunction · 0.92
TestImportRunFunction · 0.92
NewCmdImportFunction · 0.92
NewCmdSetFunction · 0.92
TestSetRunFunction · 0.92

Calls 1

FindMethod · 0.65

Tested by 3

TestImportRunFunction · 0.74
TestSetRunFunction · 0.74