Add token rotation
This commit is contained in:
@@ -20,6 +20,7 @@ type Set struct {
|
||||
specs []*spec
|
||||
longs map[string]bool
|
||||
shorts map[string]bool
|
||||
fromEnv map[string]bool
|
||||
}
|
||||
|
||||
type spec struct {
|
||||
@@ -35,6 +36,7 @@ func NewSet(name, envPrefix string) *Set {
|
||||
envPrefix: envPrefix,
|
||||
longs: map[string]bool{},
|
||||
shorts: map[string]bool{},
|
||||
fromEnv: map[string]bool{},
|
||||
}
|
||||
s.fs.Usage = func() {}
|
||||
return s
|
||||
@@ -192,6 +194,7 @@ func (s *Set) applyEnv() error {
|
||||
if err := s.fs.Set(sp.long, v); err != nil {
|
||||
return fmt.Errorf("%s: %w", s.envName(sp.long), err)
|
||||
}
|
||||
s.fromEnv[sp.long] = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -208,6 +211,31 @@ func (s *Set) Parse(args []string) error {
|
||||
return s.fs.Parse(args)
|
||||
}
|
||||
|
||||
// Changed reports whether an option was given on the command line.
|
||||
//
|
||||
// Values picked up from the environment do not count: a command that acts only
|
||||
// on the options you actually typed must not quietly act on a SEND_ variable
|
||||
// exported for the server.
|
||||
func (s *Set) Changed(long string) bool {
|
||||
if s.fromEnv[long] {
|
||||
return false
|
||||
}
|
||||
short := ""
|
||||
for _, sp := range s.specs {
|
||||
if sp.long == long {
|
||||
short = sp.short
|
||||
break
|
||||
}
|
||||
}
|
||||
given := false
|
||||
s.fs.Visit(func(f *flag.Flag) {
|
||||
if f.Name == long || (short != "" && f.Name == short) {
|
||||
given = true
|
||||
}
|
||||
})
|
||||
return given
|
||||
}
|
||||
|
||||
// PrintUsage renders the options in the "-x, --xxx" form the convention implies.
|
||||
func (s *Set) PrintUsage(w io.Writer, header string) {
|
||||
fmt.Fprint(w, header)
|
||||
|
||||
Reference in New Issue
Block a user