-
Notifications
You must be signed in to change notification settings - Fork 1
/
vpnShowGroups.go
43 lines (36 loc) · 968 Bytes
/
vpnShowGroups.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
package cmd
import (
"github.com/sam7r/nordnm/nordvpn"
"github.com/sam7r/nordnm/utils"
"os"
"github.com/jedib0t/go-pretty/table"
"github.com/spf13/cobra"
)
// vpnShowGroupsCmd represents the vpn command
var vpnShowGroupsCmd = &cobra.Command{
Use: "groups",
Short: "Show available groups",
Long: `Show all available groups, these can be used to target specific servers via the list command using --group={IDENTIFIER}`,
Run: func(cmd *cobra.Command, args []string) {
resp, err := nordvpn.GetGroups()
if err != nil {
utils.Logger.Errorf("Getting groups failed: %v", err)
}
// create new table for output
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"ID", "NAME", "IDENTIFIER"})
for _, group := range resp {
// create output rows
t.AppendRow([]interface{}{
group.ID,
group.Title,
group.Identifier,
})
}
t.Render()
},
}
func init() {
vpnShowCmd.AddCommand(vpnShowGroupsCmd)
}