@@ -23,7 +23,6 @@ import (
23
23
24
24
"github.com/arduino/arduino-cloud-cli/config"
25
25
"github.com/arduino/arduino-cloud-cli/internal/iot"
26
- iotclient "github.com/arduino/iot-client-go"
27
26
)
28
27
29
28
// CloneParams contains the parameters needed to clone a thing.
@@ -39,16 +38,9 @@ func Clone(ctx context.Context, params *CloneParams, cred *config.Credentials) (
39
38
return nil , err
40
39
}
41
40
42
- thing , err := retrieve (ctx , iotClient , params .CloneID )
41
+ newThing , err := iotClient . ThingClone (ctx , params . CloneID , params .Name )
43
42
if err != nil {
44
- return nil , err
45
- }
46
-
47
- thing .Name = & params .Name
48
- force := true
49
- newThing , err := iotClient .ThingCreate (ctx , thing , force )
50
- if err != nil {
51
- return nil , err
43
+ return nil , fmt .Errorf ("cloning thing %s: %w" , params .CloneID , err )
52
44
}
53
45
54
46
t , err := getThingInfo (newThing )
@@ -57,30 +49,3 @@ func Clone(ctx context.Context, params *CloneParams, cred *config.Credentials) (
57
49
}
58
50
return t , nil
59
51
}
60
-
61
- type thingFetcher interface {
62
- ThingShow (ctx context.Context , id string ) (* iotclient.ArduinoThing , error )
63
- }
64
-
65
- func retrieve (ctx context.Context , fetcher thingFetcher , thingID string ) (* iotclient.ThingCreate , error ) {
66
- clone , err := fetcher .ThingShow (ctx , thingID )
67
- if err != nil {
68
- return nil , fmt .Errorf ("%s: %w" , "retrieving the thing to be cloned" , err )
69
- }
70
-
71
- thing := & iotclient.ThingCreate {}
72
-
73
- // Copy variables
74
- for _ , p := range clone .Properties {
75
- thing .Properties = append (thing .Properties , iotclient.Property {
76
- Name : p .Name ,
77
- Permission : p .Permission ,
78
- UpdateParameter : p .UpdateParameter ,
79
- UpdateStrategy : p .UpdateStrategy ,
80
- Type : p .Type ,
81
- VariableName : p .VariableName ,
82
- })
83
- }
84
-
85
- return thing , nil
86
- }
0 commit comments