mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 10:40:27 +00:00
Merge pull request #258 from neilalexander/yggdrasilctl
Make yggdrasilctl less crashy
This commit is contained in:
commit
2995f24534
@ -37,13 +37,15 @@ func main() {
|
||||
endpoint := defaults.GetDefaults().DefaultAdminListen
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n", os.Args[0])
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n\n", os.Args[0])
|
||||
fmt.Println("Options:")
|
||||
flag.PrintDefaults()
|
||||
fmt.Println("Commands:\n - Use \"list\" for a list of available commands")
|
||||
fmt.Println("\nPlease note that options must always specified BEFORE the command\non the command line or they will be ignored.\n")
|
||||
fmt.Println("Commands:\n - Use \"list\" for a list of available commands\n")
|
||||
fmt.Println("Examples:")
|
||||
fmt.Println(" - ", os.Args[0], "list")
|
||||
fmt.Println(" - ", os.Args[0], "getPeers")
|
||||
fmt.Println(" - ", os.Args[0], "-v getSelf")
|
||||
fmt.Println(" - ", os.Args[0], "setTunTap name=auto mtu=1500 tap_mode=false")
|
||||
fmt.Println(" - ", os.Args[0], "-endpoint=tcp://localhost:9001 getDHT")
|
||||
fmt.Println(" - ", os.Args[0], "-endpoint=unix:///var/run/ygg.sock getDHT")
|
||||
@ -122,11 +124,20 @@ func main() {
|
||||
|
||||
for c, a := range args {
|
||||
if c == 0 {
|
||||
if strings.HasPrefix(a, "-") {
|
||||
logger.Printf("Ignoring flag %s as it should be specified before other parameters\n", a)
|
||||
continue
|
||||
}
|
||||
logger.Printf("Sending request: %v\n", a)
|
||||
send["request"] = a
|
||||
continue
|
||||
}
|
||||
tokens := strings.Split(a, "=")
|
||||
if len(tokens) == 1 {
|
||||
send[tokens[0]] = true
|
||||
} else if len(tokens) > 2 {
|
||||
send[tokens[0]] = strings.Join(tokens[1:], "=")
|
||||
} else if len(tokens) == 2 {
|
||||
if i, err := strconv.Atoi(tokens[1]); err == nil {
|
||||
logger.Printf("Sending parameter %s: %d\n", tokens[0], i)
|
||||
send[tokens[0]] = i
|
||||
@ -142,6 +153,7 @@ func main() {
|
||||
logger.Printf("Sending parameter %s: %v\n", tokens[0], send[tokens[0]])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := encoder.Encode(&send); err != nil {
|
||||
panic(err)
|
||||
@ -188,7 +200,7 @@ func main() {
|
||||
if !keysOrdered {
|
||||
for k := range slv.(map[string]interface{}) {
|
||||
if !*verbose {
|
||||
if k == "box_pub_key" || k == "box_sig_key" {
|
||||
if k == "box_pub_key" || k == "box_sig_key" || k == "nodeinfo" {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user