-
Notifications
You must be signed in to change notification settings - Fork 17
/
cmd.go
63 lines (51 loc) · 1.38 KB
/
cmd.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package devices
import (
"github.com/spf13/cobra"
"github.com/foundriesio/fioctl/client"
"github.com/foundriesio/fioctl/subcommands"
)
var (
api *client.Api
listLimit int
)
var cmd = &cobra.Command{
Use: "devices",
Aliases: []string{"device"},
Short: "Manage devices registered to a factory",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
api = subcommands.Login(cmd)
},
}
var configCmd = &cobra.Command{
Use: "config",
Short: "Device configuration",
}
var updatesCmd = &cobra.Command{
Use: "updates <device> [<update-id>]",
Short: "Show updates performed on a device",
Args: cobra.RangeArgs(1, 2),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 1 {
doListUpdates(cmd, args)
} else {
doShowUpdate(cmd, args)
}
},
Example: `
# List all updates performed on a device:
fioctl devices updates <device1>
# List the last 2 updates:
fioctl devices updates <device> -n2
# Show the details of an update:
fioctl devices updates <device> <update-id>
# Show the most recent update with bash help:
fioctl devices updates <device> $(fioctl devices updates <device> -n1 | tail -n1 | cut -f1 -d\ )
`,
}
func NewCommand() *cobra.Command {
subcommands.RequireFactory(cmd)
updatesCmd.Flags().IntVarP(&listLimit, "limit", "n", 0, "Limit the number of updates displayed.")
cmd.AddCommand(configCmd)
cmd.AddCommand(updatesCmd)
return cmd
}