diff --git a/command/alias_test.go b/command/alias_test.go index 8cb618b3b..d5276e461 100644 --- a/command/alias_test.go +++ b/command/alias_test.go @@ -200,6 +200,7 @@ aliases: {"gh ia vilmibm", []string{"issue", "list", `--author=vilmibm`, `--assignee=vilmibm`}, ""}, {"gh ia $coolmoney$", []string{"issue", "list", `--author=$coolmoney$`, `--assignee=$coolmoney$`}, ""}, {"gh pr status", []string{"pr", "status"}, ""}, + {"gh il vilmibm epic -R vilmibm/testing", []string{"issue", "list", "--author=vilmibm", "--label=epic", "-R", "vilmibm/testing"}, ""}, {"gh dne", []string{"dne"}, ""}, {"gh", []string{}, ""}, {"", []string{}, ""}, diff --git a/command/root.go b/command/root.go index 1e09651d2..6c1f39c66 100644 --- a/command/root.go +++ b/command/root.go @@ -482,10 +482,11 @@ func ExpandAlias(args []string) ([]string, error) { } if aliases.Exists(args[1]) { + extraArgs := []string{} expansion := aliases.Get(args[1]) for i, a := range args[2:] { if !strings.Contains(expansion, "$") { - expansion += " " + a + extraArgs = append(extraArgs, a) } else { expansion = strings.ReplaceAll(expansion, fmt.Sprintf("$%d", i+1), a) } @@ -494,7 +495,15 @@ func ExpandAlias(args []string) ([]string, error) { if lingeringRE.MatchString(expansion) { return empty, fmt.Errorf("not enough arguments for alias: %s", expansion) } - return shlex.Split(expansion) + + newArgs, err := shlex.Split(expansion) + if err != nil { + return nil, err + } + + newArgs = append(newArgs, extraArgs...) + + return newArgs, nil } return args[1:], nil