-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate.go
49 lines (41 loc) · 1.31 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package thing
import (
"fmt"
"github.com/arduino/iot-cloud-cli/command/thing"
"github.com/spf13/cobra"
)
var createFlags struct {
name string
deviceID string
template string
cloneID string
}
func initCreateCommand() *cobra.Command {
createCommand := &cobra.Command{
Use: "create",
Short: "Create a thing",
Long: "Create a thing for Arduino IoT Cloud",
RunE: runCreateCommand,
}
createCommand.Flags().StringVarP(&createFlags.name, "name", "n", "", "Thing name")
createCommand.Flags().StringVarP(&createFlags.deviceID, "device-id", "d", "", "ID of Device to bind to the new thing")
createCommand.Flags().StringVarP(&createFlags.cloneID, "clone-id", "c", "", "ID of Thing to be cloned")
createCommand.Flags().StringVarP(&createFlags.template, "template", "t", "", "File containing a thing template")
createCommand.MarkFlagRequired("name")
return createCommand
}
func runCreateCommand(cmd *cobra.Command, args []string) error {
fmt.Printf("Creating thing with name %s\n", createFlags.name)
params := &thing.CreateParams{
Name: createFlags.name,
DeviceID: createFlags.deviceID,
Template: createFlags.template,
CloneID: createFlags.cloneID,
}
thingID, err := thing.Create(params)
if err != nil {
return err
}
fmt.Printf("IoT Cloud thing created with ID: %s\n", thingID)
return nil
}