-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathping.go
48 lines (39 loc) · 1.25 KB
/
ping.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
package ping
import (
"github.com/arduino/iot-cloud-cli/command/ping"
"github.com/spf13/cobra"
)
var (
host string
device string
secret string
thing string
troubleshooting bool
)
func NewCommand() *cobra.Command {
pingCommand := &cobra.Command{
Use: "ping",
Short: "Ping Arduino IoT Cloud",
Long: "Ping Arduino IoT Cloud",
RunE: runPingCommand,
}
pingCommand.Flags().StringVarP(&host, "host", "b", "tcps://mqtts-up.iot.arduino.cc:8884", "MQTT Broker URL")
pingCommand.Flags().StringVarP(&device, "device", "d", "", "Device ID")
pingCommand.Flags().StringVarP(&secret, "secret", "s", "", "Device Secret")
pingCommand.Flags().StringVarP(&thing, "thing", "t", "", "Thing ID")
pingCommand.Flags().BoolVar(&troubleshooting, "troubleshooting", false, "Enable troubleshooting mode (full logs from the MQTT client)")
pingCommand.MarkFlagRequired("device")
pingCommand.MarkFlagRequired("secret")
pingCommand.MarkFlagRequired("thing")
return pingCommand
}
func runPingCommand(cmd *cobra.Command, args []string) error {
params := &ping.Params{
Host: host,
Username: device,
Password: secret,
ThingID: thing,
Troubleshooting: troubleshooting,
}
return ping.Ping(params)
}