cmd/vehicle: error if vehicle creation has failed (#9130)

This commit is contained in:
andig 2023-07-26 21:00:18 +02:00 • committed by GitHub
parent e0c340eea2
commit 29dbb687c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/evcc-io/evcc/api"
"github.com/spf13/cobra"
"golang.org/x/exp/maps"
)
// vehicleCmd represents the vehicle command
@ -52,9 +53,17 @@ func runVehicle(cmd *cobra.Command, args []string) {
if err != nil {
log.FATAL.Fatal(err)
}
vehicles = map[string]api.Vehicle{name: vehicle}
}
// check single vehicle for error
if len(vehicles) == 1 {
if err, ok := maps.Values(vehicles)[0].(error); ok {
fatal(err)
}
}
var flagUsed bool
for _, v := range vehicles {
if cmd.Flags().Lookup(flagWakeup).Changed {

View file

@ -48,6 +48,11 @@ func New(name string, other map[string]interface{}, err error) api.Vehicle {
return v
}
// Error returns the initialization error
func (v *Wrapper) Error() string {
return v.err.Error()
}
var _ api.Vehicle = (*Wrapper)(nil)
// Title implements the api.Vehicle interface