File tree 3 files changed +14
-14
lines changed
3 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import (
25
25
"github.com/arduino/arduino-cloud-cli/internal/config"
26
26
"github.com/arduino/arduino-cloud-cli/internal/iot"
27
27
"github.com/arduino/arduino-cloud-cli/internal/template"
28
+ "github.com/sirupsen/logrus"
28
29
)
29
30
30
31
// ExtractParams contains the parameters needed to
@@ -58,20 +59,19 @@ func Extract(params *ExtractParams) error {
58
59
return err
59
60
}
60
61
61
- templ , err := template .FromDashboard (dashboard )
62
- if err != nil {
63
- return err
64
- }
62
+ templ := template .FromDashboard (dashboard )
65
63
66
64
if params .Outfile == nil {
67
65
name , ok := templ ["name" ].(string )
68
66
if name == "" || ! ok {
69
67
return errors .New ("dashboard template does not have a valid name" )
70
68
}
71
- outfile := name + "-dashboard" + "." + params .Format
69
+ name = strings .Join (strings .Fields (name ), "" )
70
+ outfile := name + "-dashboard." + params .Format
72
71
params .Outfile = & outfile
73
72
}
74
73
74
+ logrus .Infof ("Extracting template in file: %s" , * params .Outfile )
75
75
err = template .ToFile (templ , * params .Outfile , params .Format )
76
76
if err != nil {
77
77
return fmt .Errorf ("saving template: %w" , err )
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import (
25
25
"github.com/arduino/arduino-cloud-cli/internal/config"
26
26
"github.com/arduino/arduino-cloud-cli/internal/iot"
27
27
"github.com/arduino/arduino-cloud-cli/internal/template"
28
+ "github.com/sirupsen/logrus"
28
29
)
29
30
30
31
// ExtractParams contains the parameters needed to
@@ -58,20 +59,19 @@ func Extract(params *ExtractParams) error {
58
59
return err
59
60
}
60
61
61
- templ , err := template .FromThing (thing )
62
- if err != nil {
63
- return err
64
- }
62
+ templ := template .FromThing (thing )
65
63
66
64
if params .Outfile == nil {
67
65
name , ok := templ ["name" ].(string )
68
66
if name == "" || ! ok {
69
67
return errors .New ("thing template does not have a valid name" )
70
68
}
71
- outfile := name + "." + params .Format
69
+ name = strings .Join (strings .Fields (name ), "" )
70
+ outfile := name + "-thing." + params .Format
72
71
params .Outfile = & outfile
73
72
}
74
73
74
+ logrus .Infof ("Extracting template in file: %s" , * params .Outfile )
75
75
err = template .ToFile (templ , * params .Outfile , params .Format )
76
76
if err != nil {
77
77
return fmt .Errorf ("saving template: %w" , err )
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ import (
29
29
)
30
30
31
31
// 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 {} {
33
33
template := make (map [string ]interface {})
34
34
template ["name" ] = thing .Name
35
35
@@ -47,11 +47,11 @@ func FromThing(thing *iotclient.ArduinoThing) (map[string]interface{}, error) {
47
47
}
48
48
template ["variables" ] = props
49
49
50
- return template , nil
50
+ return template
51
51
}
52
52
53
53
// 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 {} {
55
55
template := make (map [string ]interface {})
56
56
template ["name" ] = dashboard .Name
57
57
@@ -94,7 +94,7 @@ func FromDashboard(dashboard *iotclient.ArduinoDashboardv2) (map[string]interfac
94
94
if len (widgets ) > 0 {
95
95
template ["widgets" ] = widgets
96
96
}
97
- return template , nil
97
+ return template
98
98
}
99
99
100
100
// ToFile takes a generic template and saves it into a file,
You can’t perform that action at this time.
0 commit comments