forked from toolshed/abra
chore: bump deps
This commit is contained in:
27
vendor/github.com/spf13/pflag/README.md
generated
vendored
27
vendor/github.com/spf13/pflag/README.md
generated
vendored
@ -284,6 +284,33 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
### Using pflag with go test
|
||||
`pflag` does not parse the shorthand versions of go test's built-in flags (i.e., those starting with `-test.`).
|
||||
For more context, see issues [#63](https://github.com/spf13/pflag/issues/63) and [#238](https://github.com/spf13/pflag/issues/238) for more details.
|
||||
|
||||
For example, if you use pflag in your `TestMain` function and call `pflag.Parse()` after defining your custom flags, running a test like this:
|
||||
```bash
|
||||
go test /your/tests -run ^YourTest -v --your-test-pflags
|
||||
```
|
||||
will result in the `-v` flag being ignored. This happens because of the way pflag handles flag parsing, skipping over go test's built-in shorthand flags.
|
||||
To work around this, you can use the `ParseSkippedFlags` function, which ensures that go test's flags are parsed separately using the standard flag package.
|
||||
|
||||
**Example**: You want to parse go test flags that are otherwise ignore by `pflag.Parse()`
|
||||
```go
|
||||
import (
|
||||
goflag "flag"
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
var ip *int = flag.Int("flagname", 1234, "help message for flagname")
|
||||
|
||||
func main() {
|
||||
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
|
||||
flag.ParseSkippedFlags(os.Args[1:], goflag.CommandLine)
|
||||
flag.Parse()
|
||||
}
|
||||
```
|
||||
|
||||
## More info
|
||||
|
||||
You can see the full reference documentation of the pflag package
|
||||
|
Reference in New Issue
Block a user