cmd/vehicle: error if vehicle creation has failed (#9130)
This commit is contained in:
parent
e0c340eea2
commit
29dbb687c0
2 changed files with 14 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue