Skip to content

Commit 1774d4a

Browse files
committed
adding mor specific ws server and port flag options; backwards compatible with config usage
1 parent fba85b9 commit 1774d4a

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

cmd/call-api-client/main.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ func usage(prog string) {
3636
logrus.Fatalf("Usage: %s jsonrpc_method [jsonrpc_arguments]", prog)
3737
}
3838

39-
func ParseClientArgs() (string, string, string, interface{}, string) {
39+
func ParseClientArgs() (string, int, string, string, interface{}, string) {
4040
var wsServer, method, params, id string
41+
var wsPort int
4142

42-
flag.StringVar(&wsServer, "wsserver", "localhost", "The API host to connect to")
43+
flag.StringVar(&wsServer, "wshost", "", "The websocket host to connect to")
44+
flag.IntVar(&wsPort, "wsport", 0, "The websocket port to connect to")
4345
flag.StringVar(&method, "method", "", "JSON-RPC method")
4446
flag.StringVar(&params, "params", "", "JSON-RPC params")
4547
flag.StringVar(&id, "id", "", "JSON-RPC id")
@@ -63,7 +65,7 @@ func ParseClientArgs() (string, string, string, interface{}, string) {
6365
}
6466
}
6567

66-
return wsServer, cfgPath, method, v, id
68+
return wsServer, wsPort, cfgPath, method, v, id
6769
}
6870

6971
func closeWSConnection(c *websocket.Conn) {
@@ -80,14 +82,22 @@ func closeWSConnection(c *websocket.Conn) {
8082

8183
func main() {
8284
// parse cmdline args
83-
wsServer, cfgPath, method, params, id := ParseClientArgs()
85+
wsServer, wsPort, cfgPath, method, params, id := ParseClientArgs()
8486

8587
// read configuration
8688
cfg, err := config.NewConfig(cfgPath)
8789
if err != nil {
8890
logrus.Fatal(err)
8991
}
9092

93+
if wsServer == "" {
94+
wsServer = cfg.WSServer.Host
95+
}
96+
97+
if wsPort == 0 {
98+
wsPort = cfg.WSServer.Port
99+
}
100+
91101
// prepare logging
92102
logfile, err := config.InitLogging(cfg)
93103
if err != nil {
@@ -100,7 +110,7 @@ func main() {
100110
interrupt := make(chan os.Signal, 1)
101111
signal.Notify(interrupt, os.Interrupt)
102112

103-
api_hostport := fmt.Sprintf("%s:%d", wsServer, cfg.WSServer.Port)
113+
api_hostport := fmt.Sprintf("%s:%d", wsServer, wsPort)
104114
u := url.URL{Scheme: "ws", Host: api_hostport, Path: cfg.WSServer.Path}
105115
logrus.Printf("connecting to %s", u.String())
106116

@@ -129,7 +139,7 @@ func main() {
129139

130140
err = json.Unmarshal(message, &v)
131141
if err != nil {
132-
logrus.Println("failed to parse JSON reply: %s", err)
142+
logrus.Printf("failed to parse JSON reply: %s", err)
133143
return
134144
}
135145

0 commit comments

Comments
 (0)