forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflags.go
51 lines (37 loc) · 957 Bytes
/
flags.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
const (
flagHeaders = "log-headers"
flagHeadersDescription = "Log headers"
flagName = "name"
flagNameDescription = "Select %s by name"
flagCurrent = "current"
flagCurrentDescription = "Set maximum current"
flagEnable = "enable"
flagDisable = "disable"
flagWakeup = "wakeup"
flagWakeupDescription = "Wake up"
flagStart = "start"
flagStartDescription = "Start charging"
flagStop = "stop"
flagStopDescription = "Stop charging"
flagDigits = "digits"
flagDelay = "delay"
)
func selectByName(cmd *cobra.Command, conf *[]qualifiedConfig) error {
flag := cmd.PersistentFlags().Lookup(flagName)
if !flag.Changed {
return nil
}
name := flag.Value.String()
for _, cfg := range *conf {
if cfg.Name == name {
*conf = []qualifiedConfig{cfg}
return nil
}
}
return fmt.Errorf("%s not found", name)
}