From 27ca936b3b3c313845f9fe45d17c5cb41f7cda27 Mon Sep 17 00:00:00 2001 From: andig Date: Sat, 15 Oct 2022 12:36:20 +0200 Subject: [PATCH] Ocpp: better test command --- cmd/ocpp/main.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/cmd/ocpp/main.go b/cmd/ocpp/main.go index 71af73922..80a0558f9 100644 --- a/cmd/ocpp/main.go +++ b/cmd/ocpp/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "log" + "os" ocpp16 "github.com/lorenzodonini/ocpp-go/ocpp1.6" "github.com/lorenzodonini/ocpp-go/ocpp1.6/core" @@ -14,15 +15,33 @@ import ( "github.com/lorenzodonini/ocpp-go/ocpp1.6/types" "github.com/lorenzodonini/ocpp-go/ocppj" "github.com/lorenzodonini/ocpp-go/ws" + "github.com/spf13/cobra" ) -const ( - chargePointId = "cp0001" - url = "ws://localhost:8887" -) +var chargePointId = "cp0001" + +// ocppCmd represents the base command when called without any subcommands +var ocppCmd = &cobra.Command{ + Use: "ocpp", + Run: runOcpp, + Args: cobra.MaximumNArgs(1), +} func main() { - // chargePoint := ocpp16.NewChargePoint(chargePointId, nil, nil) + ocppCmd.Flags().String("uri", "ws://localhost:8887", "Central system uri") + + if err := ocppCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} + +func runOcpp(cmd *cobra.Command, args []string) { + url := cmd.Flags().Lookup("uri").Value.String() + + if len(args) > 0 { + chargePointId = args[0] + } // create websocket client client := ws.NewClient()