only process aliases when non-existent command passed

This commit is contained in:
vilmibm 2020-05-27 16:45:29 -05:00
parent db741a0284
commit 2627c5bb74
2 changed files with 13 additions and 5 deletions

View file

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

View file

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