summaryrefslogtreecommitdiffstats
path: root/cmd/jp/flag.go
blob: eeec98ce40cefe63d9f6257e676cf94c2971f1bb (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
	Value   string
}

// 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("must be one of [%s]", strings.Join(so.Choices, " "))
}

func (so *enumVar) String() string {
	return so.Value
}