Skip to content

Commit

Permalink
Do wildcard globbing on Windows (#1362)
Browse files Browse the repository at this point in the history
* Glob wildcards on Windows

* test/cases/globbing/0001
  • Loading branch information
johnkerl committed Aug 19, 2023
1 parent 793f52c commit 9d1d2e0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/pkg/platform/getargs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package platform
import (
"fmt"
"os"
"path/filepath"
"strings"

shellquote "github.com/kballard/go-shellquote"
Expand Down Expand Up @@ -76,7 +77,20 @@ func GetArgs() []string {
}
}
//printArgs(retargs, "NEW")
return retargs

globbed := make([]string, 0)
for i, _ := range retargs {
// Expand things like *.csv
matches, err := filepath.Glob(retargs[i])
if matches != nil && err == nil {
globbed = append(globbed, matches...)
} else {
globbed = append(globbed, retargs[i])
}
}
//printArgs(globbed, "NEW")

return globbed
}

// ----------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions test/cases/globbing/0001/a.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a,b,c
1,2,3
2 changes: 2 additions & 0 deletions test/cases/globbing/0001/b.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a,b,c
4,5,6
1 change: 1 addition & 0 deletions test/cases/globbing/0001/cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mlr --c2p cat ${CASEDIR}/*.csv
Empty file added test/cases/globbing/0001/experr
Empty file.
3 changes: 3 additions & 0 deletions test/cases/globbing/0001/expout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a b c
1 2 3
4 5 6

0 comments on commit 9d1d2e0

Please sign in to comment.