diff --git a/internal/pkg/lib/getoptify.go b/internal/pkg/lib/getoptify.go index 5af5e4e11..aa2a576e6 100644 --- a/internal/pkg/lib/getoptify.go +++ b/internal/pkg/lib/getoptify.go @@ -17,11 +17,18 @@ import ( func Getoptify(inargs []string) []string { expandRegex := regexp.MustCompile("^-[a-zA-Z0-9]+$") splitRegex := regexp.MustCompile("^--[^=]+=.+$") + numberRegex := regexp.MustCompile("^-[0-9]+$") outargs := make([]string, 0) for _, inarg := range inargs { if expandRegex.MatchString(inarg) { - for _, c := range inarg[1:] { - outargs = append(outargs, "-"+string(c)) + if numberRegex.MatchString(inarg) { + // Don't expand things like '-12345' which are (likely!) numeric arguments to verbs. + // Example: 'mlr unsparsify --fill-with -99999'. + outargs = append(outargs, inarg) + } else { + for _, c := range inarg[1:] { + outargs = append(outargs, "-"+string(c)) + } } } else if splitRegex.MatchString(inarg) { pair := strings.SplitN(inarg, "=", 2) diff --git a/test/cases/verb-unsparsify/0017/cmd b/test/cases/verb-unsparsify/0017/cmd new file mode 100644 index 000000000..6738f9aa7 --- /dev/null +++ b/test/cases/verb-unsparsify/0017/cmd @@ -0,0 +1 @@ +mlr --opprint --from test/input/needs-unsparsify.dkvp unsparsify --fill-with -12345 diff --git a/test/cases/verb-unsparsify/0017/experr b/test/cases/verb-unsparsify/0017/experr new file mode 100644 index 000000000..e69de29bb diff --git a/test/cases/verb-unsparsify/0017/expout b/test/cases/verb-unsparsify/0017/expout new file mode 100644 index 000000000..8d28a5ae4 --- /dev/null +++ b/test/cases/verb-unsparsify/0017/expout @@ -0,0 +1,6 @@ +a b c +1 -12345 -12345 +1 2 -12345 +1 2 3 +1 2 -12345 +1 -12345 -12345