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 <dest> Output destination file
<report> Optional report file <report> Optional report file
<options> <options>
-V, --verbose Print verbose output (default: "0")
-o, --print-ocr Print the OCR output to stderr -o, --print-ocr Print the OCR output to stderr
-s, --save-clip Save the image clips as PNG files (alias: save-clips) -s, --save-clip Save the image clips as PNG files (alias: save-clips)
-t, --trace Enable trace mode for detailed logging -t, --trace Enable trace mode for detailed logging
-p, --page(s) <num>["," ...] Process only the specified pages (comma-separated list) -p, --page(s) <num>["," ...] Process only the specified pages (comma-separated list)
-c, --config <file> Alternate configuration file -c, --config <file> Alternate configuration file
-l, --log(s) <string>["," ...] Logging options (comma-separated list) -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 -n, --input-name <string> Input file name when source comes from stdin
-d, --work-dir <dir> Work directory -d, --work-dir <dir> Work directory
--attempts <num> Attempts for retrying failed operations (default: "1") --attempts <num> Attempts for retrying failed operations (default: "1")

View File

@ -13,6 +13,7 @@ type cliOptionBase struct {
description string description string
isArray bool isArray bool
hidden bool hidden bool
alreadySeen bool
specialValues map[string]SpecialValueFunc specialValues map[string]SpecialValueFunc
incompatibleWith []string 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") err = errInvalidOptionValue(opt.name, boxedValue, "num-array")
} }
} else { } else {
if !opt.alreadySeen {
*opt.targetVar = []int{}
opt.alreadySeen = true
}
for value := range strings.SplitSeq(optValue, ",") { for value := range strings.SplitSeq(optValue, ",") {
var minRange, maxRange int var minRange, maxRange int
if minRange, maxRange, err = parseIntRange(value); err == nil { if minRange, maxRange, err = parseIntRange(value); err == nil {

View File

@ -55,6 +55,8 @@ func (opt *cliOptionStringArray) parse(parser cliParser, argIndex int, valuePtr
} else { } else {
err = errInvalidOptionValue(opt.name, boxedValue, "array of string") err = errInvalidOptionValue(opt.name, boxedValue, "array of string")
} }
} else if opt.alreadySeen {
*opt.targetVar = append(*opt.targetVar, strings.Split(value, ",")...)
} else { } else {
*opt.targetVar = strings.Split(value, ",") *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") err = errInvalidOptionValue(opt.name, boxedValue, "map of string")
} }
} else { } else {
if dict == nil { if dict == nil || !opt.alreadySeen {
dict = make(map[string]string) dict = make(map[string]string)
} }
for value := range strings.SplitSeq(value, ",") { for value := range strings.SplitSeq(value, ",") {