MCPcopy Create free account
hub / github.com/cli/cli / expandAlias

Function expandAlias

pkg/cmd/root/alias.go:81–104  ·  view source on GitHub ↗

ExpandAlias processes argv to see if it should be rewritten according to a user's aliases.

(expansion string, args []string)

Source from the content-addressed store, hash-verified

79
80// ExpandAlias processes argv to see if it should be rewritten according to a user's aliases.
81func expandAlias(expansion string, args []string) ([]string, error) {
82 extraArgs := []string{}
83 for i, a := range args {
84 if !strings.Contains(expansion, "$") {
85 extraArgs = append(extraArgs, a)
86 } else {
87 expansion = strings.ReplaceAll(expansion, fmt.Sprintf("$%d", i+1), a)
88 }
89 }
90
91 lingeringRE := regexp.MustCompile(`\$\d`)
92 if lingeringRE.MatchString(expansion) {
93 return nil, fmt.Errorf("not enough arguments for alias: %s", expansion)
94 }
95
96 newArgs, err := shlex.Split(expansion)
97 if err != nil {
98 return nil, err
99 }
100
101 expanded := append(newArgs, extraArgs...)
102
103 return expanded, nil
104}
105
106// ExpandShellAlias processes argv to see if it should be rewritten according to a user's aliases.
107func expandShellAlias(expansion string, args []string, findShFunc func() (string, error)) ([]string, error) {

Callers 2

NewCmdAliasFunction · 0.85
TestExpandAliasFunction · 0.85

Calls 2

ContainsMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestExpandAliasFunction · 0.68