mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 06:05:06 +03:00
Admin socket and yggdrasilctl
improvements
This refactors the request parsing, as well as improving the output for some request types. It also tweaks `yggdrasilctl` output, which should help with #947.
This commit is contained in:
parent
5ef61faeff
commit
b67c313f44
5 changed files with 193 additions and 123 deletions
|
@ -16,6 +16,8 @@ import (
|
|||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/core"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/tuntap"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/version"
|
||||
)
|
||||
|
||||
|
@ -135,6 +137,7 @@ func run() int {
|
|||
table.SetBorder(false)
|
||||
table.SetTablePadding("\t") // pad with tabs
|
||||
table.SetNoWhiteSpace(true)
|
||||
table.SetAutoWrapText(false)
|
||||
|
||||
switch strings.ToLower(recv.Request.Name) {
|
||||
case "list":
|
||||
|
@ -142,9 +145,12 @@ func run() int {
|
|||
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
table.SetHeader([]string{"Command", "Arguments"})
|
||||
table.SetHeader([]string{"Command", "Arguments", "Description"})
|
||||
for _, entry := range resp.List {
|
||||
table.Append([]string{entry.Command, strings.Join(entry.Fields, ", ")})
|
||||
for i := range entry.Fields {
|
||||
entry.Fields[i] = entry.Fields[i] + "=..."
|
||||
}
|
||||
table.Append([]string{entry.Command, strings.Join(entry.Fields, ", "), entry.Description})
|
||||
}
|
||||
table.Render()
|
||||
|
||||
|
@ -238,8 +244,31 @@ func run() int {
|
|||
break
|
||||
}
|
||||
|
||||
case "getmulticastinterfaces":
|
||||
var resp multicast.GetMulticastInterfacesResponse
|
||||
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
table.SetHeader([]string{"Interface"})
|
||||
for _, p := range resp.Interfaces {
|
||||
table.Append([]string{p})
|
||||
}
|
||||
table.Render()
|
||||
|
||||
case "gettun":
|
||||
var resp tuntap.GetTUNResponse
|
||||
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
table.Append([]string{"TUN enabled:", fmt.Sprintf("%#v", resp.Enabled)})
|
||||
if resp.Enabled {
|
||||
table.Append([]string{"Interface name:", resp.Name})
|
||||
table.Append([]string{"Interface MTU:", fmt.Sprintf("%d", resp.MTU)})
|
||||
}
|
||||
table.Render()
|
||||
|
||||
default:
|
||||
panic("unknown response type: " + recv.Request.Name)
|
||||
fmt.Println(string(recv.Response))
|
||||
}
|
||||
|
||||
return 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue