Fix issue 1032 (#1048)

* Fix issue 1032

* test files
This commit is contained in:
John Kerl 2022-07-04 16:07:12 -04:00 committed by GitHub
parent 52ce2473fb
commit 23aefb5646
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 2 deletions

View file

@ -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)

View file

@ -0,0 +1 @@
mlr --opprint --from test/input/needs-unsparsify.dkvp unsparsify --fill-with -12345

View file

View file

@ -0,0 +1,6 @@
a b c
1 -12345 -12345
1 2 -12345
1 2 3
1 2 -12345
1 -12345 -12345