prevent overriding gh commands

This commit is contained in:
vilmibm 2020-05-27 16:28:23 -05:00
parent 3552e72f7c
commit 24e97a460f
2 changed files with 16 additions and 1 deletions

View file

@ -11,7 +11,7 @@ import (
// TODO
// - [ ] DEBUG support
// - [ ] prevent overriding existing gh command
// - [x] prevent overriding existing gh command
// - [x] allow overwriting alias
// - [x] forward extra arguments
// - [x] allow duplication of placeholder
@ -68,6 +68,10 @@ func aliasSet(cmd *cobra.Command, args []string) error {
out := colorableOut(cmd)
fmt.Fprintf(out, "- Adding alias for %s: %s\n", utils.Bold(alias), utils.Bold(expansion))
if validCommand(alias) {
return fmt.Errorf("could not create alias: %q is already a gh command", alias)
}
if !validCommand(expansion) {
return fmt.Errorf("could not create alias: %s does not correspond to a gh command", utils.Bold(expansion))
}

View file

@ -9,6 +9,17 @@ import (
"github.com/cli/cli/test"
)
func TestAliasSet_gh_command(t *testing.T) {
initBlankContext("", "OWNER/REPO", "trunk")
_, err := RunCommand("alias set pr pr status")
if err == nil {
t.Fatal("expected error")
}
eq(t, err.Error(), `could not create alias: "pr" is already a gh command`)
}
func TestAliasSet_existing_alias(t *testing.T) {
cfg := `---
hosts: