diff options
| author | Tomas Aschan <[email protected]> | 2025-09-04 14:07:44 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-04 14:07:44 +0200 |
| commit | be274af2a6d762e76dcb020967844bbcf3b3dbd4 (patch) | |
| tree | 7fcd981ded4f4d1178988977094b5cae5a23852c /README.md | |
| parent | 0491e5702ad2bb108bc519a5221bcc0f52aa9564 (diff) | |
| parent | 5494e14f8cb125d5439aad4c37b344d7ea23e45b (diff) | |
Merge pull request #452 from thaJeztah/update_readme
README: update badges and minor linting fixes
Diffstat (limited to 'README.md')
| -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() } ``` |
