mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
parent
52ce2473fb
commit
23aefb5646
4 changed files with 16 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
1
test/cases/verb-unsparsify/0017/cmd
Normal file
1
test/cases/verb-unsparsify/0017/cmd
Normal file
|
|
@ -0,0 +1 @@
|
|||
mlr --opprint --from test/input/needs-unsparsify.dkvp unsparsify --fill-with -12345
|
||||
0
test/cases/verb-unsparsify/0017/experr
Normal file
0
test/cases/verb-unsparsify/0017/experr
Normal file
6
test/cases/verb-unsparsify/0017/expout
Normal file
6
test/cases/verb-unsparsify/0017/expout
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
a b c
|
||||
1 -12345 -12345
|
||||
1 2 -12345
|
||||
1 2 3
|
||||
1 2 -12345
|
||||
1 -12345 -12345
|
||||
Loading…
Add table
Add a link
Reference in a new issue