add strict attribute for gcmd.Command for strict option parsing

This commit is contained in:
John Guo
2021-11-25 14:56:15 +08:00
parent f91b5b558a
commit be0df90d05
2 changed files with 2 additions and 1 deletions

View File

@ -26,6 +26,7 @@ type Command struct {
HelpFunc Function // Custom help function
Examples string // Usage examples.
Additional string // Additional info about this command, which will be appended to the end of help info.
Strict bool // Strict parsing options, which means it returns error if invalid option given.
parent *Command // Parent command for internal usage.
commands []Command // Sub commands of this command.
}

View File

@ -97,7 +97,7 @@ func (c *Command) reParse(ctx context.Context, parser *Parser) (*Parser, error)
}
supportedOptions[optionKey] = !option.Orphan
}
return Parse(supportedOptions)
return Parse(supportedOptions, c.Strict)
}
// searchCommand recursively searches the command according given arguments.