/
remote_list.go
56 lines (45 loc) · 1.2 KB
/
remote_list.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
package dlx
import (
"os"
"github.com/bketelsen/dlx/state"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
type CmdRemoteList struct {
Cmd *cobra.Command
Global *state.Global
}
func (c *CmdRemoteList) Command() *cobra.Command {
// rlistCmd represents the rlist command
var rlistCmd = &cobra.Command{
Use: "list",
Short: "List remote LXC servers",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
RunE: c.Run,
}
return rlistCmd
}
func (c *CmdRemoteList) Run(cmd *cobra.Command, args []string) error {
conf := c.Global.Conf
remotes := conf.Remotes
defremote := conf.DefaultRemote
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Address"})
for name, remote := range remotes {
if name == defremote {
name = "*" + name
} else {
name = " " + name
}
table.Append([]string{name, remote.Addr})
}
if len(remotes) < 1 {
table.Append([]string{"{None Found}", "", ""})
}
table.Render()
return nil
}