diff --git a/command/dashboard/extract.go b/command/dashboard/extract.go index 8b2a2208..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 @@ -58,20 +59,19 @@ 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) 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 } + 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 dfeb47f4..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 @@ -58,20 +59,19 @@ 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) 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 } + 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/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,