add final checks on option values

This commit is contained in:
2026-03-05 22:30:07 +01:00
parent b5f8d9eaab
commit 95fae40d5f
15 changed files with 219 additions and 37 deletions
+8 -5
View File
@@ -38,11 +38,10 @@ func (opt *cliOptionInt) getTemplate() string {
return opt.makeOptTemplate(false, intTypeName)
}
func (opt *cliOptionInt) parse(parser cliParser, argIndex int, valuePtr *string) (skipNextArg bool, err error) {
var value string
if value, skipNextArg, err = opt.fetchOptionValue(parser, argIndex, valuePtr); err == nil {
func (opt *cliOptionInt) parse(parser cliParser, argIndex int, valuePtr *string) (skipNextArg bool, optValue string, err error) {
if optValue, skipNextArg, err = opt.fetchOptionValue(parser, argIndex, valuePtr); err == nil {
var boxedValue any
if boxedValue, err = opt.getSpecialValue(parser, value, opt.targetVar); err == nil {
if boxedValue, err = opt.getSpecialValue(parser, optValue, opt.targetVar); err == nil {
if opt.targetVar != nil {
if boxedValue != nil {
if val, ok := boxedValue.(string); ok {
@@ -51,13 +50,17 @@ func (opt *cliOptionInt) parse(parser cliParser, argIndex int, valuePtr *string)
err = errInvalidOptionValue(opt.name, boxedValue, "int")
}
} else {
*opt.targetVar, err = strconv.Atoi(value)
*opt.targetVar, err = strconv.Atoi(optValue)
}
}
}
}
return
}
func (opt *cliOptionInt) finalCheck(cliValue string) (err error) {
currentValue, _ := opt.getTargetVar()
return opt.getBase().checkValue(cliValue, currentValue)
}
func (cli *CliParser) AddIntOpt(name, short string, targetVar *int, defaultValue int, description string, aliases ...string) OptReference {
if cli.optionExists(name, short, aliases) {