value of a container option (e.g. array) is reset to empty on first specification

This commit is contained in:
Celestino Amoroso 2026-03-03 05:58:15 +01:00
parent f55e9cea82
commit ac8d5fa3a9
5 changed files with 19 additions and 11 deletions

View File

@ -85,13 +85,14 @@ where:
<dest> Output destination file
<report> Optional report file
<options>
-V, --verbose Print verbose output (default: "0")
-o, --print-ocr Print the OCR output to stderr
-s, --save-clip Save the image clips as PNG files (alias: save-clips)
-t, --trace Enable trace mode for detailed logging
-p, --page(s) <num>["," ...] Process only the specified pages (comma-separated list)
-c, --config <file> Alternate configuration file
-l, --log(s) <string>["," ...] Logging options (comma-separated list)
-V, --var(s) <key=value>["," ...] Define one or more comma separated variables for the actions context (multiple allowed)
--var(s) <key=value>["," ...] Define one or more comma separated variables for the actions context (multiple allowed)
-n, --input-name <string> Input file name when source comes from stdin
-d, --work-dir <dir> Work directory
--attempts <num> Attempts for retrying failed operations (default: "1")

View File

@ -13,6 +13,7 @@ type cliOptionBase struct {
description string
isArray bool
hidden bool
alreadySeen bool
specialValues map[string]SpecialValueFunc
incompatibleWith []string
}

View File

@ -76,6 +76,10 @@ func (opt *cliOptionIntArray) parse(parser cliParser, argIndex int, valuePtr *st
err = errInvalidOptionValue(opt.name, boxedValue, "num-array")
}
} else {
if !opt.alreadySeen {
*opt.targetVar = []int{}
opt.alreadySeen = true
}
for value := range strings.SplitSeq(optValue, ",") {
var minRange, maxRange int
if minRange, maxRange, err = parseIntRange(value); err == nil {

View File

@ -55,6 +55,8 @@ func (opt *cliOptionStringArray) parse(parser cliParser, argIndex int, valuePtr
} else {
err = errInvalidOptionValue(opt.name, boxedValue, "array of string")
}
} else if opt.alreadySeen {
*opt.targetVar = append(*opt.targetVar, strings.Split(value, ",")...)
} else {
*opt.targetVar = strings.Split(value, ",")
}

View File

@ -71,7 +71,7 @@ func (opt *cliOptionStringMap) parse(parser cliParser, argIndex int, valuePtr *s
err = errInvalidOptionValue(opt.name, boxedValue, "map of string")
}
} else {
if dict == nil {
if dict == nil || !opt.alreadySeen {
dict = make(map[string]string)
}
for value := range strings.SplitSeq(value, ",") {