]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/DaemonCommand.java
Use pattern matching switch cases
[signal-cli] / src / main / java / org / asamk / signal / commands / DaemonCommand.java
index bd6b9386779e15e06bec0557fd24e12f1c8d7374..5c1fac53499553cc0f76973ee88bfdc6704a71c6 100644 (file)
@@ -73,7 +73,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
         subparser.addArgument("--http")
                 .nargs("?")
                 .setConst("localhost:8080")
-                .help("Expose a JSON-RPC interface as http endpoint.");
+                .help("Expose a JSON-RPC interface as http endpoint (default localhost:8080).");
         subparser.addArgument("--no-receive-stdout")
                 .help("Don’t print received messages to stdout.")
                 .action(Arguments.storeTrue());
@@ -152,6 +152,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
                 !isDbusSystem
                         && socketFile == null
                         && tcpAddress == null
+                        && httpAddress == null
                         && !(inheritedChannel instanceof ServerSocketChannel)
         )) {
             runDbusSingleAccount(m, false, receiveMode != ReceiveMode.ON_START);
@@ -233,6 +234,7 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
                 !isDbusSystem
                         && socketFile == null
                         && tcpAddress == null
+                        && httpAddress == null
                         && !(inheritedChannel instanceof ServerSocketChannel)
         )) {
             runDbusMultiAccount(c, receiveMode != ReceiveMode.ON_START, false);
@@ -247,11 +249,11 @@ public class DaemonCommand implements MultiLocalCommand, LocalCommand {
     }
 
     private void addDefaultReceiveHandler(Manager m, OutputWriter outputWriter, final boolean isWeakListener) {
-        final var handler = outputWriter instanceof JsonWriter o
-                ? new JsonReceiveMessageHandler(m, o)
-                : outputWriter instanceof PlainTextWriter o
-                        ? new ReceiveMessageHandler(m, o)
-                        : Manager.ReceiveMessageHandler.EMPTY;
+        final var handler = switch (outputWriter) {
+            case PlainTextWriter writer -> new ReceiveMessageHandler(m, writer);
+            case JsonWriter writer -> new JsonReceiveMessageHandler(m, writer);
+            case null -> Manager.ReceiveMessageHandler.EMPTY;
+        };
         m.addReceiveHandler(handler, isWeakListener);
     }