Revert "Cleanup handling of flags (#4717)"
This reverts commit 98a43ad599.
This commit is contained in:
parent
98a43ad599
commit
09283f0b34
7 changed files with 60 additions and 32 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/evcc-io/evcc/cmd/shutdown"
|
||||
"github.com/evcc-io/evcc/server"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -25,12 +26,13 @@ const noCurrent = -1
|
|||
func init() {
|
||||
rootCmd.AddCommand(chargerCmd)
|
||||
chargerCmd.PersistentFlags().StringP(flagName, "n", "", fmt.Sprintf(flagNameDescription, "charger"))
|
||||
chargerCmd.Flags().IntP(flagCurrent, "I", noCurrent, flagCurrentDescription)
|
||||
chargerCmd.PersistentFlags().IntP(flagCurrent, "I", noCurrent, flagCurrentDescription)
|
||||
//lint:ignore SA1019 as Title is safe on ascii
|
||||
chargerCmd.Flags().BoolP(flagEnable, "e", false, strings.Title(flagEnable))
|
||||
chargerCmd.PersistentFlags().BoolP(flagEnable, "e", false, strings.Title(flagEnable))
|
||||
//lint:ignore SA1019 as Title is safe on ascii
|
||||
chargerCmd.Flags().BoolP(flagDisable, "d", false, strings.Title(flagDisable))
|
||||
chargerCmd.Flags().BoolP(flagWakeup, "w", false, flagWakeupDescription)
|
||||
chargerCmd.PersistentFlags().BoolP(flagDisable, "d", false, strings.Title(flagDisable))
|
||||
chargerCmd.PersistentFlags().BoolP(flagWakeup, "w", false, flagWakeupDescription)
|
||||
chargerCmd.PersistentFlags().Bool(flagHeaders, false, flagHeadersDescription)
|
||||
}
|
||||
|
||||
func runCharger(cmd *cobra.Command, args []string) {
|
||||
|
|
@ -43,10 +45,15 @@ func runCharger(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
// setup environment
|
||||
if err := configureEnvironment(cmd, conf); err != nil {
|
||||
if err := configureEnvironment(conf); err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
}
|
||||
|
||||
// full http request log
|
||||
if cmd.PersistentFlags().Lookup(flagHeaders).Changed {
|
||||
request.LogHeaders = true
|
||||
}
|
||||
|
||||
// select single charger
|
||||
if err := selectByName(cmd, &conf.Chargers); err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
|
|
@ -70,7 +77,7 @@ func runCharger(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
current := int64(noCurrent)
|
||||
if flag := cmd.Flags().Lookup(flagCurrent); flag.Changed {
|
||||
if flag := cmd.PersistentFlags().Lookup(flagCurrent); flag.Changed {
|
||||
var err error
|
||||
current, err = strconv.ParseInt(flag.Value.String(), 10, 64)
|
||||
if err != nil {
|
||||
|
|
@ -88,7 +95,7 @@ func runCharger(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Lookup(flagEnable).Changed {
|
||||
if cmd.PersistentFlags().Lookup(flagEnable).Changed {
|
||||
flagUsed = true
|
||||
|
||||
if err := v.Enable(true); err != nil {
|
||||
|
|
@ -96,7 +103,7 @@ func runCharger(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Lookup(flagDisable).Changed {
|
||||
if cmd.PersistentFlags().Lookup(flagDisable).Changed {
|
||||
flagUsed = true
|
||||
|
||||
if err := v.Enable(false); err != nil {
|
||||
|
|
@ -104,7 +111,7 @@ func runCharger(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Lookup(flagWakeup).Changed {
|
||||
if cmd.PersistentFlags().Lookup(flagWakeup).Changed {
|
||||
flagUsed = true
|
||||
|
||||
if vv, ok := v.(api.Resurrector); ok {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/evcc-io/evcc/cmd/shutdown"
|
||||
"github.com/evcc-io/evcc/server"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -26,8 +27,10 @@ var chargerRampCmd = &cobra.Command{
|
|||
func init() {
|
||||
chargerCmd.AddCommand(chargerRampCmd)
|
||||
|
||||
chargerRampCmd.Flags().StringP(flagDigits, "", "0", "fractional digits (0..2)")
|
||||
chargerRampCmd.Flags().StringP(flagDelay, "", "1s", "ramp delay")
|
||||
chargerRampCmd.PersistentFlags().StringP(flagName, "n", "", fmt.Sprintf(flagNameDescription, "charger"))
|
||||
chargerRampCmd.PersistentFlags().Bool(flagHeaders, false, flagHeadersDescription)
|
||||
chargerRampCmd.PersistentFlags().StringP(flagDigits, "", "0", "fractional digits (0..2)")
|
||||
chargerRampCmd.PersistentFlags().StringP(flagDelay, "", "1s", "ramp delay")
|
||||
}
|
||||
|
||||
func ramp(c api.Charger, digits int, delay time.Duration) {
|
||||
|
|
@ -78,10 +81,15 @@ func runChargerRamp(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
// setup environment
|
||||
if err := configureEnvironment(cmd, conf); err != nil {
|
||||
if err := configureEnvironment(conf); err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
}
|
||||
|
||||
// full http request log
|
||||
if cmd.PersistentFlags().Lookup(flagHeaders).Changed {
|
||||
request.LogHeaders = true
|
||||
}
|
||||
|
||||
// select single charger
|
||||
if err := selectByName(cmd, &conf.Chargers); err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
|
|
@ -104,12 +112,12 @@ func runChargerRamp(cmd *cobra.Command, args []string) {
|
|||
chargers = map[string]api.Charger{name: charger}
|
||||
}
|
||||
|
||||
digits, err := strconv.Atoi(cmd.Flags().Lookup(flagDigits).Value.String())
|
||||
digits, err := strconv.Atoi(cmd.PersistentFlags().Lookup(flagDigits).Value.String())
|
||||
if err != nil {
|
||||
log.ERROR.Fatalln(err)
|
||||
}
|
||||
|
||||
delay, err := time.ParseDuration(cmd.Flags().Lookup(flagDelay).Value.String())
|
||||
delay, err := time.ParseDuration(cmd.PersistentFlags().Lookup(flagDelay).Value.String())
|
||||
if err != nil {
|
||||
log.ERROR.Fatalln(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func runDump(cmd *cobra.Command, args []string) {
|
|||
|
||||
// setup environment
|
||||
if err == nil {
|
||||
err = configureEnvironment(cmd, conf)
|
||||
err = configureEnvironment(conf)
|
||||
}
|
||||
|
||||
var site *core.Site
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/server"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -20,6 +21,7 @@ var meterCmd = &cobra.Command{
|
|||
func init() {
|
||||
rootCmd.AddCommand(meterCmd)
|
||||
meterCmd.PersistentFlags().StringP(flagName, "n", "", fmt.Sprintf(flagNameDescription, "meter"))
|
||||
meterCmd.PersistentFlags().Bool(flagHeaders, false, flagHeadersDescription)
|
||||
}
|
||||
|
||||
func runMeter(cmd *cobra.Command, args []string) {
|
||||
|
|
@ -32,10 +34,15 @@ func runMeter(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
// setup environment
|
||||
if err := configureEnvironment(cmd, conf); err != nil {
|
||||
if err := configureEnvironment(conf); err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
}
|
||||
|
||||
// full http request log
|
||||
if cmd.PersistentFlags().Lookup(flagHeaders).Changed {
|
||||
request.LogHeaders = true
|
||||
}
|
||||
|
||||
// select single meter
|
||||
if err := selectByName(cmd, &conf.Meters); err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/evcc-io/evcc/server/updater"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/pipe"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/util/sponsor"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
|
|
@ -177,6 +178,11 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
|
||||
util.LogLevel(viper.GetString("log"), viper.GetStringMapString("levels"))
|
||||
|
||||
// full http request log
|
||||
if cmd.PersistentFlags().Lookup(flagHeaders).Changed {
|
||||
request.LogHeaders = true
|
||||
}
|
||||
|
||||
// network config
|
||||
if viper.GetString("uri") != "" {
|
||||
log.WARN.Println("`uri` is deprecated and will be ignored. Use `network` instead.")
|
||||
|
|
@ -214,7 +220,7 @@ func runRoot(cmd *cobra.Command, args []string) {
|
|||
|
||||
// setup environment
|
||||
if err == nil {
|
||||
err = configureEnvironment(cmd, conf)
|
||||
err = configureEnvironment(conf)
|
||||
}
|
||||
|
||||
// setup site and loadpoints
|
||||
|
|
|
|||
|
|
@ -22,12 +22,10 @@ import (
|
|||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/machine"
|
||||
"github.com/evcc-io/evcc/util/pipe"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/util/sponsor"
|
||||
"github.com/evcc-io/evcc/util/telemetry"
|
||||
"github.com/libp2p/zeroconf/v2"
|
||||
"github.com/samber/lo"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"golang.org/x/text/currency"
|
||||
)
|
||||
|
|
@ -56,12 +54,7 @@ func loadConfigFile(conf *config) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func configureEnvironment(cmd *cobra.Command, conf config) (err error) {
|
||||
// full http request log
|
||||
if cmd.PersistentFlags().Lookup(flagHeaders).Changed {
|
||||
request.LogHeaders = true
|
||||
}
|
||||
|
||||
func configureEnvironment(conf config) (err error) {
|
||||
// setup machine id
|
||||
if conf.Plant != "" {
|
||||
err = machine.CustomID(conf.Plant)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/server"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -20,9 +21,10 @@ var vehicleCmd = &cobra.Command{
|
|||
func init() {
|
||||
rootCmd.AddCommand(vehicleCmd)
|
||||
vehicleCmd.PersistentFlags().StringP(flagName, "n", "", fmt.Sprintf(flagNameDescription, "vehicle"))
|
||||
vehicleCmd.Flags().BoolP(flagStart, "a", false, flagStartDescription)
|
||||
vehicleCmd.Flags().BoolP(flagStop, "o", false, flagStopDescription)
|
||||
vehicleCmd.Flags().BoolP(flagWakeup, "w", false, flagWakeupDescription)
|
||||
vehicleCmd.PersistentFlags().BoolP(flagStart, "a", false, flagStartDescription)
|
||||
vehicleCmd.PersistentFlags().BoolP(flagStop, "o", false, flagStopDescription)
|
||||
vehicleCmd.PersistentFlags().BoolP(flagWakeup, "w", false, flagWakeupDescription)
|
||||
vehicleCmd.PersistentFlags().Bool(flagHeaders, false, flagHeadersDescription)
|
||||
}
|
||||
|
||||
func runVehicle(cmd *cobra.Command, args []string) {
|
||||
|
|
@ -35,10 +37,15 @@ func runVehicle(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
|
||||
// setup environment
|
||||
if err := configureEnvironment(cmd, conf); err != nil {
|
||||
if err := configureEnvironment(conf); err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
}
|
||||
|
||||
// full http request log
|
||||
if cmd.PersistentFlags().Lookup(flagHeaders).Changed {
|
||||
request.LogHeaders = true
|
||||
}
|
||||
|
||||
// select single vehicle
|
||||
if err := selectByName(cmd, &conf.Vehicles); err != nil {
|
||||
log.FATAL.Fatal(err)
|
||||
|
|
@ -62,7 +69,7 @@ func runVehicle(cmd *cobra.Command, args []string) {
|
|||
|
||||
var flagUsed bool
|
||||
for _, v := range vehicles {
|
||||
if cmd.Flags().Lookup(flagWakeup).Changed {
|
||||
if cmd.PersistentFlags().Lookup(flagWakeup).Changed {
|
||||
flagUsed = true
|
||||
|
||||
if vv, ok := v.(api.Resurrector); ok {
|
||||
|
|
@ -74,7 +81,7 @@ func runVehicle(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Lookup(flagStart).Changed {
|
||||
if cmd.PersistentFlags().Lookup(flagStart).Changed {
|
||||
flagUsed = true
|
||||
|
||||
if vv, ok := v.(api.VehicleChargeController); ok {
|
||||
|
|
@ -86,7 +93,7 @@ func runVehicle(cmd *cobra.Command, args []string) {
|
|||
}
|
||||
}
|
||||
|
||||
if cmd.Flags().Lookup(flagStop).Changed {
|
||||
if cmd.PersistentFlags().Lookup(flagStop).Changed {
|
||||
flagUsed = true
|
||||
|
||||
if vv, ok := v.(api.VehicleChargeController); ok {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue