forked from bpicode/fritzctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_landevices.go
60 lines (52 loc) · 1.31 KB
/
list_landevices.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
package cmd
import (
"os"
"github.com/bpicode/fritzctl/console"
"github.com/bpicode/fritzctl/fritz"
"github.com/bpicode/fritzctl/logger"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
var listLanDevicesCmd = &cobra.Command{
Use: "landevices",
Short: "List the available LAN devices",
Long: "List the available LAN devices along with several information like IP addresses, MAC addresses, etc.",
Example: "fritzctl list landevices",
RunE: listLanDevices,
}
func init() {
listCmd.AddCommand(listLanDevicesCmd)
}
func listLanDevices(cmd *cobra.Command, args []string) error {
c := clientLogin()
f := fritz.Internal(c)
devs, err := f.ListLanDevices()
assertNoError(err, "cannot obtain LAN devices data:", err)
logger.Success("Obtained LAN devices data:")
table := table()
appendData(table, *devs)
table.Render()
return nil
}
func table() *tablewriter.Table {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"NAME",
"IP",
"MAC",
"ACT/ONL",
"SPEED [Mbit/s]",
})
return table
}
func appendData(table *tablewriter.Table, devs fritz.LanDevices) {
for _, dev := range devs.Network {
table.Append([]string{
dev.Name,
dev.IP,
dev.Mac,
console.StringToCheckmark(dev.Active) + "/" + console.StringToCheckmark(dev.Online),
dev.Speed,
})
}
}