Skip to content

Commit

Permalink
Cli: hide diagnose output behind --diagnose switch (evcc-io#4845)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Oct 16, 2022
1 parent 8fc635e commit ad0591e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
7 changes: 7 additions & 0 deletions cmd/charger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func init() {
chargerCmd.Flags().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))
//lint:ignore SA1019 as Title is safe on ascii
chargerCmd.Flags().Bool(flagDiagnose, false, strings.Title(flagDiagnose))
chargerCmd.Flags().BoolP(flagWakeup, "w", false, flagWakeupDescription)
chargerCmd.Flags().IntP(flagPhases, "p", 0, flagPhasesDescription)
}
Expand Down Expand Up @@ -131,8 +133,13 @@ func runCharger(cmd *cobra.Command, args []string) {

if !flagUsed {
d := dumper{len: len(chargers)}
flag := cmd.Flags().Lookup(flagDiagnose).Changed

for name, v := range chargers {
d.DumpWithHeader(name, v)
if flag {
d.DumpDiagnosis(v)
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func (d *dumper) Dump(name string, v interface{}) {
}
}

w.Flush()
}

func (d *dumper) DumpDiagnosis(v interface{}) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)

if v, ok := v.(api.Diagnosis); ok {
fmt.Fprintln(w, "Diagnostic dump:")
v.Diagnose()
Expand Down
5 changes: 3 additions & 2 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const (
flagPhases = "phases"
flagPhasesDescription = "Set usable phases (1 or 3)"

flagEnable = "enable"
flagDisable = "disable"
flagEnable = "enable"
flagDisable = "disable"
flagDiagnose = "diagnose"

flagWakeup = "wakeup"
flagWakeupDescription = "Wake up"
Expand Down
11 changes: 9 additions & 2 deletions cmd/vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"strings"

"github.com/evcc-io/evcc/api"
"github.com/spf13/cobra"
Expand All @@ -20,6 +21,8 @@ func init() {
vehicleCmd.Flags().BoolP(flagStart, "a", false, flagStartDescription)
vehicleCmd.Flags().BoolP(flagStop, "o", false, flagStopDescription)
vehicleCmd.Flags().BoolP(flagWakeup, "w", false, flagWakeupDescription)
//lint:ignore SA1019 as Title is safe on ascii
vehicleCmd.Flags().Bool(flagDiagnose, false, strings.Title(flagDiagnose))
}

func runVehicle(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -52,8 +55,6 @@ func runVehicle(cmd *cobra.Command, args []string) {
vehicles = map[string]api.Vehicle{name: vehicle}
}

d := dumper{len: len(vehicles)}

var flagUsed bool
for _, v := range vehicles {
if cmd.Flags().Lookup(flagWakeup).Changed {
Expand Down Expand Up @@ -94,8 +95,14 @@ func runVehicle(cmd *cobra.Command, args []string) {
}

if !flagUsed {
d := dumper{len: len(vehicles)}
flag := cmd.Flags().Lookup(flagDiagnose).Changed

for name, v := range vehicles {
d.DumpWithHeader(name, v)
if flag {
d.DumpDiagnosis(v)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions vehicle/vw/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ func (v *Provider) StopCharge() error {
return v.action(ActionCharge, ActionChargeStop)
}

// var _ api.Diagnosis = (*Provider)(nil)
var _ api.Diagnosis = (*Provider)(nil)

// Diagnose implements the api.Diagnosis interface
func (v *Provider) Diagnose2() {
func (v *Provider) Diagnose() {
rr, err := v.rr()
if err != nil {
return
Expand Down

0 comments on commit ad0591e

Please sign in to comment.