diff options
| -rw-r--r-- | README.md | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -1,6 +1,7 @@ -[](https://travis-ci.org/spf13/pflag) +[](https://github.com/spf13/pflag/actions/workflows/ci.yaml) + [](https://goreportcard.com/report/github.com/spf13/pflag) -[](https://godoc.org/github.com/spf13/pflag) +[](https://pkg.go.dev/github.com/spf13/pflag) ## Description @@ -22,7 +23,7 @@ pflag is available using the standard `go get` command. Install by running: - go get github.com/spf13/pflag + go get github.com/spf13/pflag@latest Run tests by running: @@ -271,12 +272,15 @@ to support flags defined by third-party dependencies (e.g. `golang/glog`). **Example**: You want to add the Go flags to the `CommandLine` flagset ```go +package main + import ( goflag "flag" + flag "github.com/spf13/pflag" ) -var ip *int = flag.Int("flagname", 1234, "help message for flagname") +var ip = flag.Int("flagname", 1234, "help message for flagname") func main() { flag.CommandLine.AddGoFlagSet(goflag.CommandLine) @@ -296,17 +300,22 @@ will result in the `-v` flag being ignored. This happens because of the way pfla 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 +package main + import ( goflag "flag" + "os" + flag "github.com/spf13/pflag" ) -var ip *int = flag.Int("flagname", 1234, "help message for flagname") +var ip = flag.Int("flagname", 1234, "help message for flagname") func main() { flag.CommandLine.AddGoFlagSet(goflag.CommandLine) - flag.ParseSkippedFlags(os.Args[1:], goflag.CommandLine) + flag.ParseSkippedFlags(os.Args[1:], goflag.CommandLine) flag.Parse() } ``` |
