final checks on opt values moved after option parsing is complete

This commit is contained in:
2026-03-06 10:36:07 +01:00
parent 92267aec50
commit 9e28ee6545
11 changed files with 142 additions and 115 deletions
+2 -6
View File
@@ -104,16 +104,12 @@ func (cli *CliParser) parseArg(arg string, index int) (skipNextArg bool, err err
}
for i, optName := range opts {
if opt := cli.findOptionByArg(dashes + optName); opt != nil {
var optValue string
if equalPresent && i == len(opts)-1 {
_, optValue, err = opt.parse(cli, index, &value)
_, _, err = opt.parse(cli, index, &value)
} else if i < len(opts)-1 && opt.requiresValue() {
err = errMissingOptionValue(dashes + optName)
} else {
skipNextArg, optValue, err = opt.parse(cli, index, nil)
}
if err == nil && i == len(opts)-1 {
err = opt.finalCheck(optValue)
skipNextArg, _, err = opt.parse(cli, index, nil)
}
} else {
err = errUnknownOption(dashes + optName)