better placeholder handling

This commit is contained in:
vilmibm 2020-05-27 15:59:28 -05:00
parent bace327634
commit e37b517211
3 changed files with 12 additions and 1 deletions

View file

@ -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)

View file

@ -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{}, ""},

View file

@ -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)