Add docstrings for NewArgParser... functions.

This commit is contained in:
Nick Tobey
2023-04-19 11:36:48 -07:00
parent ebcaabc5b4
commit f86c44db47

View File

@@ -57,10 +57,9 @@ type ArgParser struct {
ArgListHelp [][2]string
}
func NewArgParserWithVariableArgs(name string) *ArgParser {
return NewArgParserWithMaxArgs(name, -1)
}
// NewArgParserWithMaxArgs creates a new ArgParser for a named command that limits how many positional arguments it
// will accept. If additional arguments are provided, parsing will return an error with a detailed error message,
// using the provided command name.
func NewArgParserWithMaxArgs(name string, maxArgs int) *ArgParser {
tooManyArgsErrorGenerator := func(receivedArgs []string) error {
args := strings.Join(receivedArgs, ", ")
@@ -79,6 +78,12 @@ func NewArgParserWithMaxArgs(name string, maxArgs int) *ArgParser {
}
}
// NewArgParserWithVariableArgs creates a new ArgParser for a named command
// that accepts any number of positional arguments.
func NewArgParserWithVariableArgs(name string) *ArgParser {
return NewArgParserWithMaxArgs(name, -1)
}
// SupportOption adds support for a new argument with the option given. Options must have a unique name and abbreviated name.
func (ap *ArgParser) SupportOption(opt *Option) {
name := opt.Name