diff --git a/cmd/status-cli/README.md b/cmd/status-cli/README.md index c80223b2d..e665047bd 100644 --- a/cmd/status-cli/README.md +++ b/cmd/status-cli/README.md @@ -30,7 +30,7 @@ You can also run `make status-cli` in the root directory to build the binary. ./status-cli serve -n charlie -p 8565 -a ``` -You can send direct messages through terminal or JSON RPC. +You can send direct messages through JSON RPC. If you also want to send messages through terminal enable `interactive` mode (with the `-i` flag) JSON RPC examples: diff --git a/cmd/status-cli/main.go b/cmd/status-cli/main.go index 66c1cd1ab..e9f901123 100644 --- a/cmd/status-cli/main.go +++ b/cmd/status-cli/main.go @@ -76,6 +76,11 @@ var ServeFlags = append([]cli.Flag{ Value: 8545, Usage: "HTTP Server port to listen on", }, + &cli.BoolFlag{ + Name: InteractiveFlag, + Aliases: []string{"i"}, + Usage: "Use interactive mode to input the messages", + }, }, CommonFlags...) var logger *zap.SugaredLogger diff --git a/cmd/status-cli/serve.go b/cmd/status-cli/serve.go index 29be29d39..025dae1e2 100644 --- a/cmd/status-cli/serve.go +++ b/cmd/status-cli/serve.go @@ -32,6 +32,8 @@ func serve(cCtx *cli.Context) error { port := cCtx.Int(PortFlag) apiModules := cCtx.String(APIModulesFlag) telemetryUrl := cCtx.String(TelemetryServerURLFlag) + interactive := cCtx.Bool(InteractiveFlag) + dest := cCtx.String(AddFlag) cli, err := start(name, port, apiModules, telemetryUrl) if err != nil { @@ -55,7 +57,7 @@ func serve(cCtx *cli.Context) error { logger.Infof("message received: %v (ID=%v)", message.Text, message.ID) // if request contact, accept it if message.ContentType == protobuf.ChatMessage_SYSTEM_MESSAGE_MUTUAL_EVENT_SENT { - if err = cli.sendContactRequestAcceptance(cCtx.Context, message.ID); err != nil { + if err := cli.sendContactRequestAcceptance(cCtx.Context, message.ID); err != nil { logger.Errorf("accepting contact request: %v", err) return } @@ -65,7 +67,6 @@ func serve(cCtx *cli.Context) error { })) // Send contact request - dest := cCtx.String(AddFlag) if dest != "" { err := cli.sendContactRequest(cCtx.Context, dest) if err != nil { @@ -76,17 +77,16 @@ func serve(cCtx *cli.Context) error { // nightly testrunner looks for this log to consider node as started logger.Info("retrieve messages...") - ctx, cancel := context.WithCancel(cCtx.Context) - go func() { - // Wait for signal to exit - sig := make(chan os.Signal, 1) - signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) - <-sig - cancel() - }() - - // Send message if mutual contact exists - interactiveSendMessageLoop(ctx, cli) + if interactive { + ctx, cancel := context.WithCancel(cCtx.Context) + go func() { + waitForSigExit() + cancel() + }() + interactiveSendMessageLoop(ctx, cli) + } else { + waitForSigExit() + } logger.Info("Exiting") @@ -99,3 +99,9 @@ type MobileSignalEvent struct { Messages []*common.Message `json:"messages"` } `json:"event"` } + +func waitForSigExit() { + sig := make(chan os.Signal, 1) + signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) + <-sig +}