File tree Expand file tree Collapse file tree 3 files changed +14
-14
lines changed
Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import (
2525 "github.com/arduino/arduino-cloud-cli/internal/config"
2626 "github.com/arduino/arduino-cloud-cli/internal/iot"
2727 "github.com/arduino/arduino-cloud-cli/internal/template"
28+ "github.com/sirupsen/logrus"
2829)
2930
3031// ExtractParams contains the parameters needed to
@@ -58,20 +59,19 @@ func Extract(params *ExtractParams) error {
5859 return err
5960 }
6061
61- templ , err := template .FromDashboard (dashboard )
62- if err != nil {
63- return err
64- }
62+ templ := template .FromDashboard (dashboard )
6563
6664 if params .Outfile == nil {
6765 name , ok := templ ["name" ].(string )
6866 if name == "" || ! ok {
6967 return errors .New ("dashboard template does not have a valid name" )
7068 }
71- outfile := name + "-dashboard" + "." + params .Format
69+ name = strings .Join (strings .Fields (name ), "" )
70+ outfile := name + "-dashboard." + params .Format
7271 params .Outfile = & outfile
7372 }
7473
74+ logrus .Infof ("Extracting template in file: %s" , * params .Outfile )
7575 err = template .ToFile (templ , * params .Outfile , params .Format )
7676 if err != nil {
7777 return fmt .Errorf ("saving template: %w" , err )
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import (
2525 "github.com/arduino/arduino-cloud-cli/internal/config"
2626 "github.com/arduino/arduino-cloud-cli/internal/iot"
2727 "github.com/arduino/arduino-cloud-cli/internal/template"
28+ "github.com/sirupsen/logrus"
2829)
2930
3031// ExtractParams contains the parameters needed to
@@ -58,20 +59,19 @@ func Extract(params *ExtractParams) error {
5859 return err
5960 }
6061
61- templ , err := template .FromThing (thing )
62- if err != nil {
63- return err
64- }
62+ templ := template .FromThing (thing )
6563
6664 if params .Outfile == nil {
6765 name , ok := templ ["name" ].(string )
6866 if name == "" || ! ok {
6967 return errors .New ("thing template does not have a valid name" )
7068 }
71- outfile := name + "." + params .Format
69+ name = strings .Join (strings .Fields (name ), "" )
70+ outfile := name + "-thing." + params .Format
7271 params .Outfile = & outfile
7372 }
7473
74+ logrus .Infof ("Extracting template in file: %s" , * params .Outfile )
7575 err = template .ToFile (templ , * params .Outfile , params .Format )
7676 if err != nil {
7777 return fmt .Errorf ("saving template: %w" , err )
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import (
2929)
3030
3131// FromThing extracts a template of type map[string]interface{} from a thing.
32- func FromThing (thing * iotclient.ArduinoThing ) ( map [string ]interface {}, error ) {
32+ func FromThing (thing * iotclient.ArduinoThing ) map [string ]interface {} {
3333 template := make (map [string ]interface {})
3434 template ["name" ] = thing .Name
3535
@@ -47,11 +47,11 @@ func FromThing(thing *iotclient.ArduinoThing) (map[string]interface{}, error) {
4747 }
4848 template ["variables" ] = props
4949
50- return template , nil
50+ return template
5151}
5252
5353// FromDashboard extracts a template of type map[string]interface{} from a dashboard.
54- func FromDashboard (dashboard * iotclient.ArduinoDashboardv2 ) ( map [string ]interface {}, error ) {
54+ func FromDashboard (dashboard * iotclient.ArduinoDashboardv2 ) map [string ]interface {} {
5555 template := make (map [string ]interface {})
5656 template ["name" ] = dashboard .Name
5757
@@ -94,7 +94,7 @@ func FromDashboard(dashboard *iotclient.ArduinoDashboardv2) (map[string]interfac
9494 if len (widgets ) > 0 {
9595 template ["widgets" ] = widgets
9696 }
97- return template , nil
97+ return template
9898}
9999
100100// ToFile takes a generic template and saves it into a file,
You can’t perform that action at this time.
0 commit comments