-
Notifications
You must be signed in to change notification settings - Fork 1
/
connList.go
53 lines (44 loc) · 1.16 KB
/
connList.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
package cmd
import (
"github.com/sam7r/nordnm/nmcli"
"github.com/sam7r/nordnm/utils"
"os"
"github.com/jedib0t/go-pretty/table"
"github.com/spf13/cobra"
)
var showActiveConn bool
var showAllConn bool
// connListCmd represents the vpn command
var connListCmd = &cobra.Command{
Use: "list",
Short: "List managed VPN connections",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
out, err := nmcli.ListConnections(showActiveConn)
if showAllConn != true {
out.FilterByType("vpn")
utils.Logger.Info(out)
}
if err != nil {
utils.Logger.Infof("Showing connections failed: %v", err)
}
// TODO: add active state to the table
// create new table for output
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"NAME", "UUID"})
for _, conn := range out {
// create output rows
t.AppendRow([]interface{}{
conn.Name,
conn.UUID,
})
}
t.Render()
},
}
func init() {
connCmd.AddCommand(connListCmd)
connListCmd.Flags().BoolVarP(&showActiveConn, "active", "", false, "show only active connections")
connListCmd.Flags().BoolVarP(&showAllConn, "all", "", false, "show all connections, not just vpn")
}