Skip to content

Commit

Permalink
Merge pull request #104 from akamensky/fix-subcommand-error-reporting
Browse files Browse the repository at this point in the history
When subcommand must be present but not provided the error must be triggered
  • Loading branch information
akamensky committed Jul 28, 2022
2 parents d561062 + 8317d87 commit 65ad70c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions command.go
Expand Up @@ -68,7 +68,13 @@ func (o *Command) parseSubCommands(args *[]string) error {
if err != nil {
return err
}
if v.happened {
return nil
}
}
// If we got here, there were subcommands to parse,
// but none were found, so return an error
return newSubCommandError(o)
}
return nil
}
Expand Down Expand Up @@ -137,7 +143,7 @@ func (o *Command) parseArguments(args *[]string) error {
// Will parse provided list of arguments
// common usage would be to pass directly os.Args
func (o *Command) parse(args *[]string) error {
// If we already been parsed do nothing
// If already been parsed do nothing
if o.parsed {
return nil
}
Expand All @@ -157,7 +163,7 @@ func (o *Command) parse(args *[]string) error {
}
}

// Set happened status to true when command happend
// Set happened status to true when command happened
o.happened = true

// Reduce arguments by removing Command name
Expand Down

0 comments on commit 65ad70c

Please sign in to comment.