mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 20:00:27 +00:00
Allow JSON output using -json argument
This commit is contained in:
parent
61c640dbde
commit
cc4ee91279
@ -13,11 +13,12 @@ type admin_info map[string]interface{}
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
server := flag.String("endpoint", "localhost:9001", "Admin socket endpoint")
|
server := flag.String("endpoint", "localhost:9001", "Admin socket endpoint")
|
||||||
|
injson := flag.Bool("json", false, "Output in JSON format")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
args := flag.Args()
|
args := flag.Args()
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
fmt.Println("usage:", os.Args[0], "[-endpoint=localhost:9001] command [key=value] [...]")
|
fmt.Println("usage:", os.Args[0], "[-endpoint=localhost:9001] [-json] command [key=value] [...]")
|
||||||
fmt.Println("example:", os.Args[0], "getPeers")
|
fmt.Println("example:", os.Args[0], "getPeers")
|
||||||
fmt.Println("example:", os.Args[0], "setTunTap name=auto mtu=1500 tap_mode=false")
|
fmt.Println("example:", os.Args[0], "setTunTap name=auto mtu=1500 tap_mode=false")
|
||||||
fmt.Println("example:", os.Args[0], "-endpoint=localhost:9001 getDHT")
|
fmt.Println("example:", os.Args[0], "-endpoint=localhost:9001 getDHT")
|
||||||
@ -78,6 +79,13 @@ func main() {
|
|||||||
req := recv["request"].(map[string]interface{})
|
req := recv["request"].(map[string]interface{})
|
||||||
res := recv["response"].(map[string]interface{})
|
res := recv["response"].(map[string]interface{})
|
||||||
|
|
||||||
|
if *injson {
|
||||||
|
if json, err := json.MarshalIndent(res, "", " "); err == nil {
|
||||||
|
fmt.Println(string(json))
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
switch req["request"] {
|
switch req["request"] {
|
||||||
case "dot":
|
case "dot":
|
||||||
fmt.Println(res["dot"])
|
fmt.Println(res["dot"])
|
||||||
|
Loading…
Reference in New Issue
Block a user