blob: 533b35d32f9ea556d58c6737a9a3a8de9183f96b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package main
import (
"fmt"
"strings"
)
type enumVar struct {
Choices []string // The acceptable choices the user may pass to the flag
Value string // the current value of the flag
}
// Set implements the flag.Value interface.
func (so *enumVar) Set(v string) error {
for _, c := range so.Choices {
if c == v {
so.Value = v
return nil
}
}
return fmt.Errorf("invalid choice; must be one of %s", strings.Join(so.Choices, ","))
}
func (so *enumVar) String() string {
return so.Value
}
|