]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/RemoteDeleteCommand.java
Refactor output writers
[signal-cli] / src / main / java / org / asamk / signal / commands / RemoteDeleteCommand.java
index 796a3344d9007e793d2e93b4fd434ad0d64e28be..0ab68a902b5575fb783beed4ea3f23b4e800f667 100644 (file)
@@ -4,6 +4,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
 import net.sourceforge.argparse4j.inf.Subparser;
 
 import org.asamk.Signal;
+import org.asamk.signal.OutputWriter;
 import org.asamk.signal.PlainTextWriterImpl;
 import org.asamk.signal.commands.exceptions.CommandException;
 import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@@ -15,21 +16,22 @@ import org.freedesktop.dbus.exceptions.DBusExecutionException;
 
 import java.util.List;
 
-import static org.asamk.signal.util.ErrorUtils.handleAssertionError;
-
 public class RemoteDeleteCommand implements DbusCommand {
 
-    @Override
-    public void attachToSubparser(final Subparser subparser) {
+    private final OutputWriter outputWriter;
+
+    public RemoteDeleteCommand(final OutputWriter outputWriter) {
+        this.outputWriter = outputWriter;
+    }
+
+    public static void attachToSubparser(final Subparser subparser) {
         subparser.help("Remotely delete a previously sent message.");
         subparser.addArgument("-t", "--target-timestamp")
                 .required(true)
                 .type(long.class)
                 .help("Specify the timestamp of the message to delete.");
-        subparser.addArgument("-g", "--group")
-                .help("Specify the recipient group ID.");
-        subparser.addArgument("recipient")
-                .help("Specify the recipients' phone number.").nargs("*");
+        subparser.addArgument("-g", "--group").help("Specify the recipient group ID.");
+        subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
     }
 
     @Override
@@ -45,9 +47,9 @@ public class RemoteDeleteCommand implements DbusCommand {
             throw new UserErrorException("You cannot specify recipients by phone number and groups at the same time");
         }
 
-        final long targetTimestamp = ns.getLong("target_timestamp");
+        final long targetTimestamp = ns.getLong("target-timestamp");
 
-        final var writer = new PlainTextWriterImpl(System.out);
+        final var writer = (PlainTextWriterImpl) outputWriter;
 
         byte[] groupId = null;
         if (groupIdString != null) {
@@ -66,9 +68,6 @@ public class RemoteDeleteCommand implements DbusCommand {
                 timestamp = signal.sendRemoteDeleteMessage(targetTimestamp, recipients);
             }
             writer.println("{}", timestamp);
-        } catch (AssertionError e) {
-            handleAssertionError(e);
-            throw e;
         } catch (UnknownObject e) {
             throw new UserErrorException("Failed to find dbus object, maybe missing the -u flag: " + e.getMessage());
         } catch (Signal.Error.InvalidNumber e) {