From bace3276340c3276a534a2d74fe6d3a07da175e6 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Wed, 27 May 2020 15:36:07 -0500 Subject: [PATCH] pass rest of args through --- command/alias_test.go | 1 + command/root.go | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/command/alias_test.go b/command/alias_test.go index 3e1660d85..3932d6af3 100644 --- a/command/alias_test.go +++ b/command/alias_test.go @@ -148,6 +148,7 @@ aliases: {"gh co", []string{"pr", "checkout"}, ""}, {"gh il", nil, `not enough arguments for alias: issue list --author="$1" --label="$2"`}, {"gh il vilmibm", nil, `not enough arguments for alias: issue list --author="vilmibm" --label="$2"`}, + {"gh co 123", []string{"pr", "checkout", "123"}, ""}, {"gh il vilmibm epic", []string{"issue", "list", `--author=vilmibm`, `--label=epic`}, ""}, {"gh pr status", []string{"pr", "status"}, ""}, {"gh dne", []string{"dne"}, ""}, diff --git a/command/root.go b/command/root.go index 7ed0fc7de..1fe790a40 100644 --- a/command/root.go +++ b/command/root.go @@ -483,13 +483,15 @@ func ExpandAlias(args []string) ([]string, error) { if aliases.Exists(args[1]) { expansion := aliases.Get(args[1]) + for i, a := range args[2:] { + if !strings.Contains(expansion, "$") { + expansion += " " + a + } else { + expansion = strings.ReplaceAll(expansion, fmt.Sprintf("$%d", i+1), a) + } + } if strings.Contains(expansion, "$") { - for i, a := range args[2:] { - expansion = strings.Replace(expansion, fmt.Sprintf("$%d", i+1), a, 1) - } - if strings.Contains(expansion, "$") { - return empty, fmt.Errorf("not enough arguments for alias: %s", expansion) - } + return empty, fmt.Errorf("not enough arguments for alias: %s", expansion) } return shlex.Split(expansion) }