diff --git a/cmd/gh/main.go b/cmd/gh/main.go index d7d29c7fb..b4ddcb302 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -32,10 +32,18 @@ func main() { stderr := utils.NewColorable(os.Stderr) - expandedArgs, err := command.ExpandAlias(os.Args) - if err != nil { - fmt.Fprintf(stderr, "failed to process aliases: %s\n", err) - os.Exit(2) + expandedArgs := []string{} + if len(os.Args) > 0 { + expandedArgs = os.Args[1:] + } + + cmd, _, err := command.RootCmd.Traverse(expandedArgs) + if err != nil || cmd == command.RootCmd { + expandedArgs, err = command.ExpandAlias(os.Args) + if err != nil { + fmt.Fprintf(stderr, "failed to process aliases: %s\n", err) + os.Exit(2) + } } command.RootCmd.SetArgs(expandedArgs) diff --git a/command/alias.go b/command/alias.go index f3a09603c..541422b58 100644 --- a/command/alias.go +++ b/command/alias.go @@ -11,7 +11,7 @@ import ( // TODO // - [ ] DEBUG support -// - [ ] give our commands precedence +// - [x] give our commands precedence // - [x] prevent overriding existing gh command // - [x] allow overwriting alias // - [x] forward extra arguments