forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflags.go
72 lines (55 loc) · 1.8 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package cmd
import (
"github.com/spf13/cobra"
)
const (
flagHeaders = "log-headers"
flagHeadersDescription = "Log headers"
flagIgnoreDatabase = "ignore-db"
flagIgnoreDatabaseDescription = "Run command ignoring service database"
flagBatteryMode = "battery-mode"
flagBatteryModeDescription = "Set battery mode (normal, hold, charge)"
flagBatteryModeWait = "battery-mode-wait"
flagBatteryModeWaitDescription = "Wait given duration during which potential watchdogs are active"
flagCurrent = "current"
flagCurrentDescription = "Set maximum current"
flagPhases = "phases"
flagPhasesDescription = "Set usable phases (1 or 3)"
flagCloud = "cloud"
flagCloudDescription = "Use cloud service (requires sponsor token)"
flagReset = "reset"
flagResetDescription = "Reset migrated settings"
flagEnable = "enable"
flagDisable = "disable"
flagDiagnose = "diagnose"
flagDiagnoseDescription = "Diagnose"
flagWakeup = "wakeup"
flagWakeupDescription = "Wake up"
flagStart = "start"
flagStartDescription = "Start charging"
flagStop = "stop"
flagStopDescription = "Stop charging"
flagRepeat = "repeat"
flagRepeatDescription = "Repeat until interrupted"
flagDigits = "digits"
flagDelay = "delay"
flagForce = "force"
)
func bind(cmd *cobra.Command, key string, flagName ...string) {
name := key
if len(flagName) == 1 {
name = flagName[0]
}
if err := viper.BindPFlag(key, cmd.Flags().Lookup(name)); err != nil {
panic(err)
}
}
func bindP(cmd *cobra.Command, key string, flagName ...string) {
name := key
if len(flagName) == 1 {
name = flagName[0]
}
if err := viper.BindPFlag(key, cmd.PersistentFlags().Lookup(name)); err != nil {
panic(err)
}
}