prevent overriding gh commands
This commit is contained in:
parent
3552e72f7c
commit
24e97a460f
2 changed files with 16 additions and 1 deletions
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue