jessevdk / go-flags

go command line option parser
http://godoc.org/github.com/jessevdk/go-flags
BSD 3-Clause "New" or "Revised" License
2.59k stars 308 forks source link

feat: support field tag prefix and custom field tag names #410

Open donkeywon opened 3 months ago

donkeywon commented 3 months ago

To avoid tag conflicts with other third-party libraries like env

  1. support field tag prefix
    
    type Cfg struct {
    Path string `flag-short:"p" flag-long:"path" flag-description:"path to xxx"`
    }

cfg := &Cfg{} parser := flags.NewParser(cfg, flags.Default, flags.FlagTagPrefix("flag-")) parser.Parse()

2. support custom field tags name
```go
type Cfg struct {
    Path string `flag-custom-short:"p" long:"path" description:"path to xxx"`
}

flagTags := flags.NewFlagTags()
flagTags.Short = "flag-custom-short"
cfg := &Cfg{}
parser := flags.NewParser(cfg, flags.Default, flags.CustomFlagTags(flagTags))
parser.Parse()