-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdelete.go
40 lines (33 loc) · 976 Bytes
/
delete.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
package device
import (
"os"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/iot-cloud-cli/command/device"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var deleteFlags struct {
id string
}
func initDeleteCommand() *cobra.Command {
deleteCommand := &cobra.Command{
Use: "delete",
Short: "Delete a device",
Long: "Delete a device from Arduino IoT Cloud",
Run: runDeleteCommand,
}
deleteCommand.Flags().StringVarP(&deleteFlags.id, "id", "i", "", "Device ID")
deleteCommand.MarkFlagRequired("id")
return deleteCommand
}
func runDeleteCommand(cmd *cobra.Command, args []string) {
logrus.Infof("Deleting device %s\n", deleteFlags.id)
params := &device.DeleteParams{ID: deleteFlags.id}
err := device.Delete(params)
if err != nil {
feedback.Errorf("Error during device delete: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
logrus.Info("Device successfully deleted")
}