cli/token: fix database vehicles ignored (#24716)

This commit is contained in:
andig 2025-10-25 09:22:42 +02:00 • committed by GitHub
parent 7ac7e037df
commit 9e151d65ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,12 +2,10 @@ package cmd
import (
"fmt"
"slices"
"strings"
"github.com/evcc-io/evcc/util/config"
"github.com/evcc-io/evcc/util/templates"
"github.com/samber/lo"
"github.com/spf13/cobra"
"golang.org/x/oauth2"
)
@ -31,28 +29,17 @@ func runToken(cmd *cobra.Command, args []string) {
// setup environment
if err := configureEnvironment(cmd, &conf); err != nil {
fatal(err)
log.FATAL.Fatal(err)
}
var vehicleConf config.Named
if len(conf.Vehicles) == 1 {
vehicleConf = conf.Vehicles[0]
} else if len(args) == 1 {
idx := slices.IndexFunc(conf.Vehicles, func(v config.Named) bool {
return strings.EqualFold(v.Name, args[0])
})
if idx >= 0 {
vehicleConf = conf.Vehicles[idx]
}
if err := configureVehicles(conf.Vehicles, args...); err != nil {
log.FATAL.Fatal(err)
}
if vehicleConf.Name == "" {
vehicles := lo.Map(conf.Vehicles, func(v config.Named, _ int) string {
return v.Name
})
log.FATAL.Fatalf("vehicle not found, have %v", vehicles)
}
vehicles := config.Vehicles().Devices()
for _, dev := range vehicles {
vehicleConf := dev.Config()
var token *oauth2.Token
var err error
@ -100,4 +87,5 @@ func runToken(cmd *cobra.Command, args []string) {
fmt.Println(" access:", token.AccessToken)
fmt.Println(" refresh:", token.RefreshToken)
}
}
}