]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/DaemonCommand.java
Remove deprecated --json parameter
[signal-cli] / src / main / java / org / asamk / signal / commands / DaemonCommand.java
index 7de0a71f0b46c34d5c8bf46eaf0c1004a4bd832d..8cafea103e229107c8b919fd7ee7d94565e7b440 100644 (file)
@@ -8,6 +8,8 @@ import org.asamk.signal.DbusConfig;
 import org.asamk.signal.DbusReceiveMessageHandler;
 import org.asamk.signal.JsonDbusReceiveMessageHandler;
 import org.asamk.signal.OutputType;
 import org.asamk.signal.DbusReceiveMessageHandler;
 import org.asamk.signal.JsonDbusReceiveMessageHandler;
 import org.asamk.signal.OutputType;
+import org.asamk.signal.commands.exceptions.CommandException;
+import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
 import org.asamk.signal.dbus.DbusSignalImpl;
 import org.asamk.signal.manager.Manager;
 import org.freedesktop.dbus.connections.impl.DBusConnection;
 import org.asamk.signal.dbus.DbusSignalImpl;
 import org.asamk.signal.manager.Manager;
 import org.freedesktop.dbus.connections.impl.DBusConnection;
@@ -18,6 +20,7 @@ import org.slf4j.LoggerFactory;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 public class DaemonCommand implements MultiLocalCommand {
 import java.util.concurrent.TimeUnit;
 
 public class DaemonCommand implements MultiLocalCommand {
@@ -26,27 +29,25 @@ public class DaemonCommand implements MultiLocalCommand {
 
     @Override
     public void attachToSubparser(final Subparser subparser) {
 
     @Override
     public void attachToSubparser(final Subparser subparser) {
+        subparser.help("Run in daemon mode and provide an experimental dbus interface.");
         subparser.addArgument("--system")
                 .action(Arguments.storeTrue())
                 .help("Use DBus system bus instead of user bus.");
         subparser.addArgument("--ignore-attachments")
                 .help("Don’t download attachments of received messages.")
                 .action(Arguments.storeTrue());
         subparser.addArgument("--system")
                 .action(Arguments.storeTrue())
                 .help("Use DBus system bus instead of user bus.");
         subparser.addArgument("--ignore-attachments")
                 .help("Don’t download attachments of received messages.")
                 .action(Arguments.storeTrue());
-        subparser.addArgument("--json")
-                .help("WARNING: This parameter is now deprecated! Please use the global \"--output=json\" option instead.\n\nOutput received messages in json format, one json object per line.")
-                .action(Arguments.storeTrue());
     }
 
     @Override
     }
 
     @Override
-    public int handleCommand(final Namespace ns, final Manager m) {
-        boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
+    public Set<OutputType> getSupportedOutputTypes() {
+        return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON);
+    }
 
 
-        // TODO delete later when "json" variable is removed
-        if (ns.getBoolean("json")) {
-            logger.warn("\"--json\" option has been deprecated, please use the global \"--output=json\" instead.");
-        }
+    @Override
+    public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
+        var inJson = ns.get("output") == OutputType.JSON;
 
 
-        boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
+        boolean ignoreAttachments = ns.getBoolean("ignore-attachments");
 
         DBusConnection.DBusBusType busType;
         if (ns.getBoolean("system")) {
 
         DBusConnection.DBusBusType busType;
         if (ns.getBoolean("system")) {
@@ -55,9 +56,9 @@ public class DaemonCommand implements MultiLocalCommand {
             busType = DBusConnection.DBusBusType.SESSION;
         }
 
             busType = DBusConnection.DBusBusType.SESSION;
         }
 
-        try (DBusConnection conn = DBusConnection.getConnection(busType)) {
-            String objectPath = DbusConfig.getObjectPath();
-            Thread t = run(conn, objectPath, m, ignoreAttachments, inJson);
+        try (var conn = DBusConnection.getConnection(busType)) {
+            var objectPath = DbusConfig.getObjectPath();
+            var t = run(conn, objectPath, m, ignoreAttachments, inJson);
 
             conn.requestBusName(DbusConfig.getBusname());
 
 
             conn.requestBusName(DbusConfig.getBusname());
 
@@ -65,23 +66,17 @@ public class DaemonCommand implements MultiLocalCommand {
                 t.join();
             } catch (InterruptedException ignored) {
             }
                 t.join();
             } catch (InterruptedException ignored) {
             }
-            return 0;
         } catch (DBusException | IOException e) {
             logger.error("Dbus command failed", e);
         } catch (DBusException | IOException e) {
             logger.error("Dbus command failed", e);
-            return 2;
+            throw new UnexpectedErrorException("Dbus command failed");
         }
     }
 
     @Override
         }
     }
 
     @Override
-    public int handleCommand(final Namespace ns, final List<Manager> managers) {
-        boolean inJson = ns.get("output") == OutputType.JSON || ns.getBoolean("json");
-
-        // TODO delete later when "json" variable is removed
-        if (ns.getBoolean("json")) {
-            logger.warn("\"--json\" option has been deprecated, please use the global \"--output=json\" instead.");
-        }
+    public void handleCommand(final Namespace ns, final List<Manager> managers) throws CommandException {
+        var inJson = ns.get("output") == OutputType.JSON;
 
 
-        boolean ignoreAttachments = ns.getBoolean("ignore_attachments");
+        boolean ignoreAttachments = ns.getBoolean("ignore-attachments");
 
         DBusConnection.DBusBusType busType;
         if (ns.getBoolean("system")) {
 
         DBusConnection.DBusBusType busType;
         if (ns.getBoolean("system")) {
@@ -90,26 +85,25 @@ public class DaemonCommand implements MultiLocalCommand {
             busType = DBusConnection.DBusBusType.SESSION;
         }
 
             busType = DBusConnection.DBusBusType.SESSION;
         }
 
-        try (DBusConnection conn = DBusConnection.getConnection(busType)) {
-            List<Thread> receiveThreads = new ArrayList<>();
-            for (Manager m : managers) {
-                String objectPath = DbusConfig.getObjectPath(m.getUsername());
-                Thread thread = run(conn, objectPath, m, ignoreAttachments, inJson);
+        try (var conn = DBusConnection.getConnection(busType)) {
+            var receiveThreads = new ArrayList<Thread>();
+            for (var m : managers) {
+                var objectPath = DbusConfig.getObjectPath(m.getUsername());
+                var thread = run(conn, objectPath, m, ignoreAttachments, inJson);
                 receiveThreads.add(thread);
             }
 
             conn.requestBusName(DbusConfig.getBusname());
 
                 receiveThreads.add(thread);
             }
 
             conn.requestBusName(DbusConfig.getBusname());
 
-            for (Thread t : receiveThreads) {
+            for (var t : receiveThreads) {
                 try {
                     t.join();
                 } catch (InterruptedException ignored) {
                 }
             }
                 try {
                     t.join();
                 } catch (InterruptedException ignored) {
                 }
             }
-            return 0;
         } catch (DBusException | IOException e) {
             logger.error("Dbus command failed", e);
         } catch (DBusException | IOException e) {
             logger.error("Dbus command failed", e);
-            return 2;
+            throw new UnexpectedErrorException("Dbus command failed");
         }
     }
 
         }
     }
 
@@ -118,7 +112,7 @@ public class DaemonCommand implements MultiLocalCommand {
     ) throws DBusException {
         conn.exportObject(objectPath, new DbusSignalImpl(m));
 
     ) throws DBusException {
         conn.exportObject(objectPath, new DbusSignalImpl(m));
 
-        final Thread thread = new Thread(() -> {
+        final var thread = new Thread(() -> {
             while (true) {
                 try {
                     m.receiveMessages(1,
             while (true) {
                 try {
                     m.receiveMessages(1,