MCPcopy
hub / github.com/cli/cli / ValidAliasNameFunc

Function ValidAliasNameFunc

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

ValidAliasNameFunc returns a function that will check if the given string is a valid alias name. A name is valid if: - it does not shadow an existing command, - it is not nested under a command that is runnable, - it is not nested under a command that does not exist.

(cmd *cobra.Command)

Source from the content-addressed store, hash-verified

13// - it is not nested under a command that is runnable,
14// - it is not nested under a command that does not exist.
15func ValidAliasNameFunc(cmd *cobra.Command) func(string) bool {
16 return func(args string) bool {
17 split, err := shlex.Split(args)
18 if err != nil || len(split) == 0 {
19 return false
20 }
21
22 rootCmd := cmd.Root()
23 foundCmd, foundArgs, _ := rootCmd.Find(split)
24 if foundCmd != nil && !foundCmd.Runnable() && len(foundArgs) == 1 {
25 return true
26 }
27
28 return false
29 }
30}
31
32// ValidAliasExpansionFunc returns a function that will check if the given string
33// is a valid alias expansion. An expansion is valid if:

Callers 6

NewCmdRootFunction · 0.92
TestImportRunFunction · 0.92
NewCmdImportFunction · 0.92
NewCmdSetFunction · 0.92
TestSetRunFunction · 0.92
TestValidAliasNameFuncFunction · 0.85

Calls 1

FindMethod · 0.65

Tested by 3

TestImportRunFunction · 0.74
TestSetRunFunction · 0.74
TestValidAliasNameFuncFunction · 0.68