flag.go 818 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package pkg
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "os"
  7. )
  8. type DeprecatedFlag struct {
  9. Name string
  10. }
  11. // IsBoolFlag is defined to allow the flag to be defined without an argument
  12. func (df *DeprecatedFlag) IsBoolFlag() bool {
  13. return true
  14. }
  15. func (df *DeprecatedFlag) Set(s string) error {
  16. log.Printf("WARNING: flag \"-%s\" is no longer supported.", df.Name)
  17. return nil
  18. }
  19. func (df *DeprecatedFlag) String() string {
  20. return ""
  21. }
  22. func UsageWithIgnoredFlagsFunc(fs *flag.FlagSet, ignore []string) func() {
  23. iMap := make(map[string]struct{}, len(ignore))
  24. for _, name := range ignore {
  25. iMap[name] = struct{}{}
  26. }
  27. return func() {
  28. fs.VisitAll(func(f *flag.Flag) {
  29. if _, ok := iMap[f.Name]; ok {
  30. return
  31. }
  32. format := " -%s=%s: %s\n"
  33. fmt.Fprintf(os.Stderr, format, f.Name, f.DefValue, f.Usage)
  34. })
  35. }
  36. }