From b3d9523721b318b512927e57ec5b099985e2e9d1 Mon Sep 17 00:00:00 2001 From: Paolo Calao Date: Tue, 12 Oct 2021 11:03:45 +0200 Subject: [PATCH 1/3] Remove useless error parameter --- command/dashboard/extract.go | 5 +---- command/thing/extract.go | 5 +---- internal/template/extract.go | 8 ++++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/command/dashboard/extract.go b/command/dashboard/extract.go index 8b2a2208..be12ae63 100644 --- a/command/dashboard/extract.go +++ b/command/dashboard/extract.go @@ -58,10 +58,7 @@ func Extract(params *ExtractParams) error { return err } - templ, err := template.FromDashboard(dashboard) - if err != nil { - return err - } + templ := template.FromDashboard(dashboard) if params.Outfile == nil { name, ok := templ["name"].(string) diff --git a/command/thing/extract.go b/command/thing/extract.go index dfeb47f4..b032e7dd 100644 --- a/command/thing/extract.go +++ b/command/thing/extract.go @@ -58,10 +58,7 @@ func Extract(params *ExtractParams) error { return err } - templ, err := template.FromThing(thing) - if err != nil { - return err - } + templ := template.FromThing(thing) if params.Outfile == nil { name, ok := templ["name"].(string) diff --git a/internal/template/extract.go b/internal/template/extract.go index 69b6adb4..0da92c59 100644 --- a/internal/template/extract.go +++ b/internal/template/extract.go @@ -29,7 +29,7 @@ import ( ) // FromThing extracts a template of type map[string]interface{} from a thing. -func FromThing(thing *iotclient.ArduinoThing) (map[string]interface{}, error) { +func FromThing(thing *iotclient.ArduinoThing) map[string]interface{} { template := make(map[string]interface{}) template["name"] = thing.Name @@ -47,11 +47,11 @@ func FromThing(thing *iotclient.ArduinoThing) (map[string]interface{}, error) { } template["variables"] = props - return template, nil + return template } // FromDashboard extracts a template of type map[string]interface{} from a dashboard. -func FromDashboard(dashboard *iotclient.ArduinoDashboardv2) (map[string]interface{}, error) { +func FromDashboard(dashboard *iotclient.ArduinoDashboardv2) map[string]interface{} { template := make(map[string]interface{}) template["name"] = dashboard.Name @@ -94,7 +94,7 @@ func FromDashboard(dashboard *iotclient.ArduinoDashboardv2) (map[string]interfac if len(widgets) > 0 { template["widgets"] = widgets } - return template, nil + return template } // ToFile takes a generic template and saves it into a file, From 522e964944973d6796d52ff7a85b1f1184a58336 Mon Sep 17 00:00:00 2001 From: Paolo Calao Date: Tue, 12 Oct 2021 11:18:15 +0200 Subject: [PATCH 2/3] Strip spaces from exctracted template names --- command/dashboard/extract.go | 3 ++- command/thing/extract.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/command/dashboard/extract.go b/command/dashboard/extract.go index be12ae63..8493ae7e 100644 --- a/command/dashboard/extract.go +++ b/command/dashboard/extract.go @@ -65,7 +65,8 @@ func Extract(params *ExtractParams) error { if name == "" || !ok { return errors.New("dashboard template does not have a valid name") } - outfile := name + "-dashboard" + "." + params.Format + name = strings.Join(strings.Fields(name), "") + outfile := name + "-dashboard." + params.Format params.Outfile = &outfile } diff --git a/command/thing/extract.go b/command/thing/extract.go index b032e7dd..ff3fb5cb 100644 --- a/command/thing/extract.go +++ b/command/thing/extract.go @@ -65,7 +65,8 @@ func Extract(params *ExtractParams) error { if name == "" || !ok { return errors.New("thing template does not have a valid name") } - outfile := name + "." + params.Format + name = strings.Join(strings.Fields(name), "") + outfile := name + "-thing." + params.Format params.Outfile = &outfile } From 509a423f9c2ce89771b02fc5fe05857932d21d73 Mon Sep 17 00:00:00 2001 From: Paolo Calao Date: Tue, 12 Oct 2021 14:32:51 +0200 Subject: [PATCH 3/3] Extraction: Log destination file --- command/dashboard/extract.go | 2 ++ command/thing/extract.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/command/dashboard/extract.go b/command/dashboard/extract.go index 8493ae7e..672071b6 100644 --- a/command/dashboard/extract.go +++ b/command/dashboard/extract.go @@ -25,6 +25,7 @@ import ( "github.com/arduino/arduino-cloud-cli/internal/config" "github.com/arduino/arduino-cloud-cli/internal/iot" "github.com/arduino/arduino-cloud-cli/internal/template" + "github.com/sirupsen/logrus" ) // ExtractParams contains the parameters needed to @@ -70,6 +71,7 @@ func Extract(params *ExtractParams) error { params.Outfile = &outfile } + logrus.Infof("Extracting template in file: %s", *params.Outfile) err = template.ToFile(templ, *params.Outfile, params.Format) if err != nil { return fmt.Errorf("saving template: %w", err) diff --git a/command/thing/extract.go b/command/thing/extract.go index ff3fb5cb..23866fe0 100644 --- a/command/thing/extract.go +++ b/command/thing/extract.go @@ -25,6 +25,7 @@ import ( "github.com/arduino/arduino-cloud-cli/internal/config" "github.com/arduino/arduino-cloud-cli/internal/iot" "github.com/arduino/arduino-cloud-cli/internal/template" + "github.com/sirupsen/logrus" ) // ExtractParams contains the parameters needed to @@ -70,6 +71,7 @@ func Extract(params *ExtractParams) error { params.Outfile = &outfile } + logrus.Infof("Extracting template in file: %s", *params.Outfile) err = template.ToFile(templ, *params.Outfile, params.Format) if err != nil { return fmt.Errorf("saving template: %w", err)