package cmd import ( "fmt" "strings" "github.com/andig/evcc/api" "github.com/andig/evcc/server" "github.com/andig/evcc/util" "github.com/spf13/cobra" "github.com/spf13/viper" ) // meterCmd represents the meter command var meterCmd = &cobra.Command{ Use: "meter [name]", Short: "Query configured meters", Run: runMeter, } func init() { rootCmd.AddCommand(meterCmd) } func runMeter(cmd *cobra.Command, args []string) { util.LogLevel(viper.GetString("log"), viper.GetStringMapString("levels")) log.INFO.Printf("evcc %s (%s)", server.Version, server.Commit) // load config conf := loadConfigFile(cfgFile) // setup mqtt if conf.Mqtt.Broker != "" { configureMQTT(conf.Mqtt) } if err := cp.configureMeters(conf); err != nil { cp.Close() // cleanup any open sessions log.FATAL.Fatal(err) } defer cp.Close() // cleanup on exit meters := cp.meters if len(args) == 1 { arg := args[0] meters = map[string]api.Meter{arg: cp.Meter(arg)} } w := dumpFormat() for name, v := range meters { if len(meters) != 1 { fmt.Fprintln(w, name) fmt.Fprintln(w, strings.Repeat("-", len(name))) } dumpAPIs(w, v) if len(meters) != 1 { fmt.Fprintln(w) } w.Flush() } }