forked from rexray/rexray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmds_adapter.go
65 lines (56 loc) · 1.36 KB
/
cmds_adapter.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
64
65
package cli
import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/spf13/cobra"
)
func (c *CLI) initAdapterCmdsAndFlags() {
c.initAdapterCmds()
c.initAdapterFlags()
}
func (c *CLI) initAdapterCmds() {
c.adapterCmd = &cobra.Command{
Use: "adapter",
Short: "The adapter manager",
Run: func(cmd *cobra.Command, args []string) {
if isHelpFlags(cmd) {
cmd.Usage()
} else {
c.adapterGetTypesCmd.Run(c.adapterGetTypesCmd, args)
}
},
}
c.c.AddCommand(c.adapterCmd)
c.adapterGetTypesCmd = &cobra.Command{
Use: "types",
Short: "List the available adapter types",
Aliases: []string{"ls", "list"},
Run: func(cmd *cobra.Command, args []string) {
for n := range c.r.DriverNames() {
fmt.Printf("Storage Driver: %v\n", n)
}
},
}
c.adapterCmd.AddCommand(c.adapterGetTypesCmd)
c.adapterGetInstancesCmd = &cobra.Command{
Use: "instances",
Short: "List the configured adapter instances",
Run: func(cmd *cobra.Command, args []string) {
allInstances, err := c.r.Storage.GetInstances()
if err != nil {
panic(err)
}
if len(allInstances) > 0 {
out, err := c.marshalOutput(&allInstances)
if err != nil {
log.Fatal(err)
}
fmt.Println(out)
}
},
}
c.adapterCmd.AddCommand(c.adapterGetInstancesCmd)
}
func (c *CLI) initAdapterFlags() {
c.addOutputFormatFlag(c.adapterGetInstancesCmd.Flags())
}