You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a single or series of asterisks (i.e. * or ***) are passed as the values of string flags, pflag will return a file name within the current directory instead of the asterisk strings.
Code to reproduce:
package main
import (
"fmt"
flags "github.com/spf13/pflag"
)
varcoolflagstringfuncinit() {
flags.StringVar(&coolflag, "coolflag", "", "This is a cool flag")
}
funcmain() {
flags.Parse()
ifcoolflag=="" {
flags.PrintDefaults()
return
}
fmt.Println("cool flag value: ", coolflag)
}
Execution is in a directory with the above code in main.go, a go.mod like the below, and the generated go.sum:
module flagstest
go 1.22.3
require github.com/spf13/pflag v1.0.5
Results:
jake.vanvorhis$ go run . --coolflag *
cool flag value: go.mod
jake.vanvorhis$ go run . --coolflag ***
cool flag value: go.mod
jake.vanvorhis$ go run . --coolflag hello
cool flag value: hello
I have also seen this reproduced where CODEOWNERS was the file read into the string flag value.
The text was updated successfully, but these errors were encountered:
I believe this is actually the shell expanding the glob* before passing the arguments, and it doesn't have anything to do with pflag. Try wrapping the asterisk in ':
When a single or series of asterisks (i.e.
*
or***
) are passed as the values of string flags,pflag
will return a file name within the current directory instead of the asterisk strings.Code to reproduce:
Execution is in a directory with the above code in
main.go
, ago.mod
like the below, and the generatedgo.sum
:Results:
I have also seen this reproduced where CODEOWNERS was the file read into the string flag value.
The text was updated successfully, but these errors were encountered: