From 9d1d2e07ca1314610c17db708a2b9cd4bf759bce Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 19 Aug 2023 17:40:35 -0400 Subject: [PATCH] Do wildcard globbing on Windows (#1362) * Glob wildcards on Windows * test/cases/globbing/0001 --- internal/pkg/platform/getargs_windows.go | 16 +++++++++++++++- test/cases/globbing/0001/a.csv | 2 ++ test/cases/globbing/0001/b.csv | 2 ++ test/cases/globbing/0001/cmd | 1 + test/cases/globbing/0001/experr | 0 test/cases/globbing/0001/expout | 3 +++ 6 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/cases/globbing/0001/a.csv create mode 100644 test/cases/globbing/0001/b.csv create mode 100644 test/cases/globbing/0001/cmd create mode 100644 test/cases/globbing/0001/experr create mode 100644 test/cases/globbing/0001/expout diff --git a/internal/pkg/platform/getargs_windows.go b/internal/pkg/platform/getargs_windows.go index 536a6288e..4349e4346 100644 --- a/internal/pkg/platform/getargs_windows.go +++ b/internal/pkg/platform/getargs_windows.go @@ -11,6 +11,7 @@ package platform import ( "fmt" "os" + "path/filepath" "strings" shellquote "github.com/kballard/go-shellquote" @@ -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 } // ---------------------------------------------------------------- diff --git a/test/cases/globbing/0001/a.csv b/test/cases/globbing/0001/a.csv new file mode 100644 index 000000000..bfde6bfa0 --- /dev/null +++ b/test/cases/globbing/0001/a.csv @@ -0,0 +1,2 @@ +a,b,c +1,2,3 diff --git a/test/cases/globbing/0001/b.csv b/test/cases/globbing/0001/b.csv new file mode 100644 index 000000000..a9411aa9d --- /dev/null +++ b/test/cases/globbing/0001/b.csv @@ -0,0 +1,2 @@ +a,b,c +4,5,6 diff --git a/test/cases/globbing/0001/cmd b/test/cases/globbing/0001/cmd new file mode 100644 index 000000000..a5eecc577 --- /dev/null +++ b/test/cases/globbing/0001/cmd @@ -0,0 +1 @@ +mlr --c2p cat ${CASEDIR}/*.csv diff --git a/test/cases/globbing/0001/experr b/test/cases/globbing/0001/experr new file mode 100644 index 000000000..e69de29bb diff --git a/test/cases/globbing/0001/expout b/test/cases/globbing/0001/expout new file mode 100644 index 000000000..d0c04ad13 --- /dev/null +++ b/test/cases/globbing/0001/expout @@ -0,0 +1,3 @@ +a b c +1 2 3 +4 5 6