MCPcopy Index your code
hub / github.com/cli/cli / expandAlias

Function expandAlias

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

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