proxy.go 633 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package flags
  2. import (
  3. "errors"
  4. )
  5. const (
  6. ProxyValueOff = "off"
  7. ProxyValueReadonly = "readonly"
  8. ProxyValueOn = "on"
  9. )
  10. var (
  11. ProxyValues = []string{
  12. ProxyValueOff,
  13. ProxyValueReadonly,
  14. ProxyValueOn,
  15. }
  16. )
  17. // ProxyFlag implements the flag.Value interface.
  18. type Proxy string
  19. // Set verifies the argument to be a valid member of proxyFlagValues
  20. // before setting the underlying flag value.
  21. func (pf *Proxy) Set(s string) error {
  22. for _, v := range ProxyValues {
  23. if s == v {
  24. *pf = Proxy(s)
  25. return nil
  26. }
  27. }
  28. return errors.New("invalid value")
  29. }
  30. func (pf *Proxy) String() string {
  31. return string(*pf)
  32. }