ExpandAlias processes argv to see if it should be rewritten according to a user's aliases.
(expansion string, args []string)
| 79 | |
| 80 | // ExpandAlias processes argv to see if it should be rewritten according to a user's aliases. |
| 81 | func 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. |
| 107 | func expandShellAlias(expansion string, args []string, findShFunc func() (string, error)) ([]string, error) { |