Skip to content

Commit

Permalink
feat. default command
Browse files Browse the repository at this point in the history
  • Loading branch information
w-devin committed Jul 5, 2024
1 parent 84c536d commit 9104f58
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ func (c *Command) Run(cCtx *Context, arguments ...string) (err error) {
}
}

hasGavenCommand := false
for _, arg := range arguments {
for _, cmd := range cCtx.App.Commands {
if strings.EqualFold(arg, cmd.Name) {
hasGavenCommand = true
break
}
}
}
if !hasGavenCommand {
arguments = append([]string{arguments[0], cCtx.App.DefaultCommand}, arguments[1:]...)
}

a := args(arguments)
set, err := c.parseFlags(&a, cCtx.shellComplete)
cCtx.flagSet = set
Expand Down

0 comments on commit 9104f58

Please sign in to comment.