forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeter.go
65 lines (53 loc) · 1.45 KB
/
meter.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
package cmd
import (
"fmt"
"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"
)
// meterCmd represents the meter command
var meterCmd = &cobra.Command{
Use: "meter [name]",
Short: "Query configured meters",
Run: runMeter,
}
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) {
util.LogLevel(viper.GetString("log"), viper.GetStringMapString("levels"))
log.INFO.Printf("evcc %s", server.FormattedVersion())
// load config
if err := loadConfigFile(cfgFile, &conf); err != nil {
log.FATAL.Fatal(err)
}
// setup environment
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)
}
if err := cp.configureMeters(conf); err != nil {
log.FATAL.Fatal(err)
}
meters := cp.meters
if len(args) == 1 {
arg := args[0]
meters = map[string]api.Meter{arg: cp.Meter(arg)}
}
d := dumper{len: len(meters)}
for name, v := range meters {
d.DumpWithHeader(name, v)
}
}