-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate.go
46 lines (38 loc) · 1.07 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
package device
import (
"fmt"
"github.com/bcmi-labs/iot-cloud-cli/command/device"
"github.com/spf13/cobra"
)
var createFlags struct {
port string
name string
fqbn string
}
func initCreateCommand() *cobra.Command {
createCommand := &cobra.Command{
Use: "create",
Short: "Create a device",
Long: "Create a device for Arduino IoT Cloud",
RunE: runCreateCommand,
}
createCommand.Flags().StringVarP(&createFlags.port, "port", "p", "", "Device port")
createCommand.Flags().StringVarP(&createFlags.name, "name", "n", "", "Device name")
createCommand.Flags().StringVarP(&createFlags.fqbn, "fqbn", "b", "", "Device fqbn")
createCommand.MarkFlagRequired("name")
return createCommand
}
func runCreateCommand(cmd *cobra.Command, args []string) error {
fmt.Printf("Creating device with name %s\n", createFlags.name)
params := &device.CreateParams{
Port: createFlags.port,
Name: createFlags.name,
Fqbn: createFlags.fqbn,
}
devID, err := device.Create(params)
if err != nil {
return err
}
fmt.Printf("IoT Cloud device created with ID: %s\n", devID)
return nil
}