diff --git a/command/alias.go b/command/alias.go index 7fdd7a5cf..3448f7b24 100644 --- a/command/alias.go +++ b/command/alias.go @@ -9,6 +9,13 @@ import ( "github.com/spf13/cobra" ) +// TODO +// - [ ] DEBUG support +// - [ ] prevent overriding existing gh command +// - [ ] allow overwriting alias +// - [ ] forward extra arguments +// - [ ] allow duplication of placeholder + func init() { RootCmd.AddCommand(aliasCmd) aliasCmd.AddCommand(aliasSetCmd) diff --git a/command/alias_test.go b/command/alias_test.go index 3932d6af3..1e152ca89 100644 --- a/command/alias_test.go +++ b/command/alias_test.go @@ -138,6 +138,7 @@ hosts: aliases: co: pr checkout il: issue list --author="$1" --label="$2" + ia: issue list --author="$1" --assignee="$1" ` initBlankContext(cfg, "OWNER/REPO", "trunk") for _, c := range []struct { @@ -150,6 +151,8 @@ aliases: {"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 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 dne", []string{"dne"}, ""}, {"gh", []string{}, ""}, diff --git a/command/root.go b/command/root.go index 1fe790a40..1e09651d2 100644 --- a/command/root.go +++ b/command/root.go @@ -490,7 +490,8 @@ func ExpandAlias(args []string) ([]string, error) { expansion = strings.ReplaceAll(expansion, fmt.Sprintf("$%d", i+1), a) } } - if strings.Contains(expansion, "$") { + lingeringRE := regexp.MustCompile(`\$\d`) + if lingeringRE.MatchString(expansion) { return empty, fmt.Errorf("not enough arguments for alias: %s", expansion) } return shlex.Split(expansion)