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

Function expandAlias

pkg/cmd/root/alias.go:82–105  ·  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

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