forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvehicle.go
51 lines (42 loc) · 1.05 KB
/
vehicle.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
package cmd
import (
"github.com/andig/evcc/api"
"github.com/andig/evcc/server"
"github.com/andig/evcc/util"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// vehicleCmd represents the vehicle command
var vehicleCmd = &cobra.Command{
Use: "vehicle [name]",
Short: "Query configured vehicles",
Run: runVehicle,
}
func init() {
rootCmd.AddCommand(vehicleCmd)
}
func runVehicle(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, err := loadConfigFile(cfgFile)
if err != nil {
log.FATAL.Fatal(err)
}
// setup environment
if err := configureEnvironment(conf); err != nil {
log.FATAL.Fatal(err)
}
if err := cp.configureVehicles(conf); err != nil {
log.FATAL.Fatal(err)
}
vehicles := cp.vehicles
if len(args) == 1 {
arg := args[0]
vehicles = map[string]api.Vehicle{arg: cp.Vehicle(arg)}
}
d := dumper{len: len(vehicles)}
for name, v := range vehicles {
d.DumpWithHeader(name, v)
}
}