Refactor output writers

This commit is contained in:
AsamK 2021-08-08 17:32:55 +02:00
parent f449a242e4
commit 48b2c7ff8a
42 changed files with 327 additions and 187 deletions

View file

@ -76,11 +76,10 @@ public class App {
var subparsers = parser.addSubparsers().title("subcommands").dest("command"); var subparsers = parser.addSubparsers().title("subcommands").dest("command");
final var commands = Commands.getCommands(); Commands.getCommandSubparserAttachers().forEach((key, value) -> {
for (var entry : commands.entrySet()) { var subparser = subparsers.addParser(key);
var subparser = subparsers.addParser(entry.getKey()); value.attachToSubparser(subparser);
entry.getValue().attachToSubparser(subparser); });
}
return parser; return parser;
} }
@ -90,13 +89,17 @@ public class App {
} }
public void init() throws CommandException { public void init() throws CommandException {
var outputType = ns.<OutputType>get("output");
var outputWriter = outputType == OutputType.JSON
? new JsonWriter(System.out)
: new PlainTextWriterImpl(System.out);
var commandKey = ns.getString("command"); var commandKey = ns.getString("command");
var command = Commands.getCommand(commandKey); var command = Commands.getCommand(commandKey, outputWriter);
if (command == null) { if (command == null) {
throw new UserErrorException("Command not implemented!"); throw new UserErrorException("Command not implemented!");
} }
var outputType = ns.<OutputType>get("output");
if (!command.getSupportedOutputTypes().contains(outputType)) { if (!command.getSupportedOutputTypes().contains(outputType)) {
throw new UserErrorException("Command doesn't support output type " + outputType.toString()); throw new UserErrorException("Command doesn't support output type " + outputType.toString());
} }

View file

@ -10,8 +10,8 @@ public class DbusReceiveMessageHandler extends ReceiveMessageHandler {
private final DBusConnection conn; private final DBusConnection conn;
private final String objectPath; private final String objectPath;
public DbusReceiveMessageHandler(Manager m, DBusConnection conn, final String objectPath) { public DbusReceiveMessageHandler(Manager m, PlainTextWriter writer, DBusConnection conn, final String objectPath) {
super(m); super(m, writer);
this.conn = conn; this.conn = conn;
this.objectPath = objectPath; this.objectPath = objectPath;
} }

View file

@ -21,8 +21,10 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
private final String objectPath; private final String objectPath;
public JsonDbusReceiveMessageHandler(Manager m, DBusConnection conn, final String objectPath) { public JsonDbusReceiveMessageHandler(
super(m); Manager m, JsonWriter jsonWriter, DBusConnection conn, final String objectPath
) {
super(m, jsonWriter);
this.conn = conn; this.conn = conn;
this.objectPath = objectPath; this.objectPath = objectPath;
} }

View file

@ -17,9 +17,9 @@ public class JsonReceiveMessageHandler implements Manager.ReceiveMessageHandler
protected final Manager m; protected final Manager m;
private final JsonWriter jsonWriter; private final JsonWriter jsonWriter;
public JsonReceiveMessageHandler(Manager m) { public JsonReceiveMessageHandler(Manager m, JsonWriter jsonWriter) {
this.m = m; this.m = m;
jsonWriter = new JsonWriter(System.out); this.jsonWriter = jsonWriter;
} }
@Override @Override

View file

@ -13,7 +13,7 @@ import java.io.OutputStreamWriter;
import java.io.Writer; import java.io.Writer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
public class JsonWriter { public class JsonWriter implements OutputWriter {
private final Writer writer; private final Writer writer;
private final ObjectMapper objectMapper; private final ObjectMapper objectMapper;

View file

@ -0,0 +1,5 @@
package org.asamk.signal;
public interface OutputWriter {
}

View file

@ -1,6 +1,8 @@
package org.asamk.signal; package org.asamk.signal;
public interface PlainTextWriter { import java.util.function.Consumer;
public interface PlainTextWriter extends OutputWriter {
void println(String format, Object... args); void println(String format, Object... args);
@ -10,12 +12,7 @@ public interface PlainTextWriter {
println(""); println("");
} }
default void indent(final WriterConsumer subWriter) { default void indent(final Consumer<PlainTextWriter> subWriter) {
subWriter.consume(indentedWriter()); subWriter.accept(indentedWriter());
}
interface WriterConsumer {
void consume(PlainTextWriter writer);
} }
} }

View file

@ -29,15 +29,15 @@ import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
final Manager m; final Manager m;
final PlainTextWriter writer;
public ReceiveMessageHandler(Manager m) { public ReceiveMessageHandler(Manager m, final PlainTextWriter writer) {
this.m = m; this.m = m;
this.writer = writer;
} }
@Override @Override
public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) { public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
PlainTextWriter writer = new PlainTextWriterImpl(System.out);
if (envelope.hasSource()) { if (envelope.hasSource()) {
var source = envelope.getSourceAddress(); var source = envelope.getSourceAddress();
writer.println("Envelope from: {} (device: {})", formatContact(source), envelope.getSourceDevice()); writer.println("Envelope from: {} (device: {})", formatContact(source), envelope.getSourceDevice());

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@ -20,14 +21,16 @@ public class AddDeviceCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(AddDeviceCommand.class); private final static Logger logger = LoggerFactory.getLogger(AddDeviceCommand.class);
@Override public static void attachToSubparser(final Subparser subparser) {
public void attachToSubparser(final Subparser subparser) {
subparser.help("Link another device to this device. Only works, if this is the master device."); subparser.help("Link another device to this device. Only works, if this is the master device.");
subparser.addArgument("--uri") subparser.addArgument("--uri")
.required(true) .required(true)
.help("Specify the uri contained in the QR code shown by the new device."); .help("Specify the uri contained in the QR code shown by the new device.");
} }
public AddDeviceCommand(final OutputWriter outputWriter) {
}
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
try { try {

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -18,20 +19,22 @@ public class BlockCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(BlockCommand.class); private final static Logger logger = LoggerFactory.getLogger(BlockCommand.class);
@Override public static void attachToSubparser(final Subparser subparser) {
public void attachToSubparser(final Subparser subparser) {
subparser.help("Block the given contacts or groups (no messages will be received)"); subparser.help("Block the given contacts or groups (no messages will be received)");
subparser.addArgument("contact").help("Contact number").nargs("*"); subparser.addArgument("contact").help("Contact number").nargs("*");
subparser.addArgument("-g", "--group").help("Group ID").nargs("*"); subparser.addArgument("-g", "--group").help("Group ID").nargs("*");
} }
public BlockCommand(final OutputWriter outputWriter) {
}
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
for (var contact_number : ns.<String>getList("contact")) { for (var contactNumber : ns.<String>getList("contact")) {
try { try {
m.setContactBlocked(contact_number, true); m.setContactBlocked(contactNumber, true);
} catch (InvalidNumberException e) { } catch (InvalidNumberException e) {
logger.warn("Invalid number {}: {}", contact_number, e.getMessage()); logger.warn("Invalid number {}: {}", contactNumber, e.getMessage());
} catch (NotMasterDeviceException e) { } catch (NotMasterDeviceException e) {
throw new UserErrorException("This command doesn't work on linked devices."); throw new UserErrorException("This command doesn't work on linked devices.");
} }

View file

@ -1,15 +1,11 @@
package org.asamk.signal.commands; package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputType; import org.asamk.signal.OutputType;
import java.util.Set; import java.util.Set;
public interface Command { public interface Command {
void attachToSubparser(Subparser subparser);
default Set<OutputType> getSupportedOutputTypes() { default Set<OutputType> getSupportedOutputTypes() {
return Set.of(OutputType.PLAIN_TEXT); return Set.of(OutputType.PLAIN_TEXT);
} }

View file

@ -1,58 +1,70 @@
package org.asamk.signal.commands; package org.asamk.signal.commands;
import org.asamk.signal.OutputWriter;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
public class Commands { public class Commands {
private static final Map<String, Command> commands = new TreeMap<>(); private static final Map<String, CommandConstructor> commands = new HashMap<>();
private static final Map<String, SubparserAttacher> commandSubparserAttacher = new TreeMap<>();
static { static {
addCommand("addDevice", new AddDeviceCommand()); addCommand("addDevice", AddDeviceCommand::new, AddDeviceCommand::attachToSubparser);
addCommand("block", new BlockCommand()); addCommand("block", BlockCommand::new, BlockCommand::attachToSubparser);
addCommand("daemon", new DaemonCommand()); addCommand("daemon", DaemonCommand::new, DaemonCommand::attachToSubparser);
addCommand("getUserStatus", new GetUserStatusCommand()); addCommand("getUserStatus", GetUserStatusCommand::new, GetUserStatusCommand::attachToSubparser);
addCommand("link", new LinkCommand()); addCommand("link", LinkCommand::new, LinkCommand::attachToSubparser);
addCommand("listContacts", new ListContactsCommand()); addCommand("listContacts", ListContactsCommand::new, ListContactsCommand::attachToSubparser);
addCommand("listDevices", new ListDevicesCommand()); addCommand("listDevices", ListDevicesCommand::new, ListDevicesCommand::attachToSubparser);
addCommand("listGroups", new ListGroupsCommand()); addCommand("listGroups", ListGroupsCommand::new, ListGroupsCommand::attachToSubparser);
addCommand("listIdentities", new ListIdentitiesCommand()); addCommand("listIdentities", ListIdentitiesCommand::new, ListIdentitiesCommand::attachToSubparser);
addCommand("joinGroup", new JoinGroupCommand()); addCommand("joinGroup", JoinGroupCommand::new, JoinGroupCommand::attachToSubparser);
addCommand("quitGroup", new QuitGroupCommand()); addCommand("quitGroup", QuitGroupCommand::new, QuitGroupCommand::attachToSubparser);
addCommand("receive", new ReceiveCommand()); addCommand("receive", ReceiveCommand::new, ReceiveCommand::attachToSubparser);
addCommand("register", new RegisterCommand()); addCommand("register", RegisterCommand::new, RegisterCommand::attachToSubparser);
addCommand("removeDevice", new RemoveDeviceCommand()); addCommand("removeDevice", RemoveDeviceCommand::new, RemoveDeviceCommand::attachToSubparser);
addCommand("remoteDelete", new RemoteDeleteCommand()); addCommand("remoteDelete", RemoteDeleteCommand::new, RemoteDeleteCommand::attachToSubparser);
addCommand("removePin", new RemovePinCommand()); addCommand("removePin", RemovePinCommand::new, RemovePinCommand::attachToSubparser);
addCommand("send", new SendCommand()); addCommand("send", SendCommand::new, SendCommand::attachToSubparser);
addCommand("sendContacts", new SendContactsCommand()); addCommand("sendContacts", SendContactsCommand::new, SendContactsCommand::attachToSubparser);
addCommand("sendReaction", new SendReactionCommand()); addCommand("sendReaction", SendReactionCommand::new, SendReactionCommand::attachToSubparser);
addCommand("sendSyncRequest", new SendSyncRequestCommand()); addCommand("sendSyncRequest", SendSyncRequestCommand::new, SendSyncRequestCommand::attachToSubparser);
addCommand("sendTyping", new SendTypingCommand()); addCommand("sendTyping", SendTypingCommand::new, SendTypingCommand::attachToSubparser);
addCommand("setPin", new SetPinCommand()); addCommand("setPin", SetPinCommand::new, SetPinCommand::attachToSubparser);
addCommand("trust", new TrustCommand()); addCommand("trust", TrustCommand::new, TrustCommand::attachToSubparser);
addCommand("unblock", new UnblockCommand()); addCommand("unblock", UnblockCommand::new, UnblockCommand::attachToSubparser);
addCommand("unregister", new UnregisterCommand()); addCommand("unregister", UnregisterCommand::new, UnregisterCommand::attachToSubparser);
addCommand("updateAccount", new UpdateAccountCommand()); addCommand("updateAccount", UpdateAccountCommand::new, UpdateAccountCommand::attachToSubparser);
addCommand("updateContact", new UpdateContactCommand()); addCommand("updateContact", UpdateContactCommand::new, UpdateContactCommand::attachToSubparser);
addCommand("updateGroup", new UpdateGroupCommand()); addCommand("updateGroup", UpdateGroupCommand::new, UpdateGroupCommand::attachToSubparser);
addCommand("updateProfile", new UpdateProfileCommand()); addCommand("updateProfile", UpdateProfileCommand::new, UpdateProfileCommand::attachToSubparser);
addCommand("uploadStickerPack", new UploadStickerPackCommand()); addCommand("uploadStickerPack", UploadStickerPackCommand::new, UploadStickerPackCommand::attachToSubparser);
addCommand("verify", new VerifyCommand()); addCommand("verify", VerifyCommand::new, VerifyCommand::attachToSubparser);
} }
public static Map<String, Command> getCommands() { public static Map<String, SubparserAttacher> getCommandSubparserAttachers() {
return commands; return commandSubparserAttacher;
} }
public static Command getCommand(String commandKey) { public static Command getCommand(String commandKey, OutputWriter outputWriter) {
if (!commands.containsKey(commandKey)) { if (!commands.containsKey(commandKey)) {
return null; return null;
} }
return commands.get(commandKey); return commands.get(commandKey).constructCommand(outputWriter);
} }
private static void addCommand(String name, Command command) { private static void addCommand(
commands.put(name, command); String name, CommandConstructor commandConstructor, SubparserAttacher subparserAttacher
) {
commands.put(name, commandConstructor);
commandSubparserAttacher.put(name, subparserAttacher);
}
private interface CommandConstructor {
Command constructCommand(OutputWriter outputWriter);
} }
} }

View file

@ -7,7 +7,10 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.DbusConfig; import org.asamk.signal.DbusConfig;
import org.asamk.signal.DbusReceiveMessageHandler; import org.asamk.signal.DbusReceiveMessageHandler;
import org.asamk.signal.JsonDbusReceiveMessageHandler; import org.asamk.signal.JsonDbusReceiveMessageHandler;
import org.asamk.signal.JsonWriter;
import org.asamk.signal.OutputType; import org.asamk.signal.OutputType;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
import org.asamk.signal.dbus.DbusSignalImpl; import org.asamk.signal.dbus.DbusSignalImpl;
@ -26,9 +29,9 @@ import java.util.concurrent.TimeUnit;
public class DaemonCommand implements MultiLocalCommand { public class DaemonCommand implements MultiLocalCommand {
private final static Logger logger = LoggerFactory.getLogger(DaemonCommand.class); private final static Logger logger = LoggerFactory.getLogger(DaemonCommand.class);
private final OutputWriter outputWriter;
@Override public static void attachToSubparser(final Subparser subparser) {
public void attachToSubparser(final Subparser subparser) {
subparser.help("Run in daemon mode and provide an experimental dbus interface."); subparser.help("Run in daemon mode and provide an experimental dbus interface.");
subparser.addArgument("--system") subparser.addArgument("--system")
.action(Arguments.storeTrue()) .action(Arguments.storeTrue())
@ -38,6 +41,10 @@ public class DaemonCommand implements MultiLocalCommand {
.action(Arguments.storeTrue()); .action(Arguments.storeTrue());
} }
public DaemonCommand(final OutputWriter outputWriter) {
this.outputWriter = outputWriter;
}
@Override @Override
public Set<OutputType> getSupportedOutputTypes() { public Set<OutputType> getSupportedOutputTypes() {
return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON); return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON);
@ -45,8 +52,6 @@ public class DaemonCommand implements MultiLocalCommand {
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { 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; DBusConnection.DBusBusType busType;
@ -58,7 +63,7 @@ public class DaemonCommand implements MultiLocalCommand {
try (var conn = DBusConnection.getConnection(busType)) { try (var conn = DBusConnection.getConnection(busType)) {
var objectPath = DbusConfig.getObjectPath(); var objectPath = DbusConfig.getObjectPath();
var t = run(conn, objectPath, m, ignoreAttachments, inJson); var t = run(conn, objectPath, m, ignoreAttachments);
conn.requestBusName(DbusConfig.getBusname()); conn.requestBusName(DbusConfig.getBusname());
@ -74,8 +79,6 @@ public class DaemonCommand implements MultiLocalCommand {
@Override @Override
public void handleCommand(final Namespace ns, final List<Manager> managers) throws CommandException { 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; DBusConnection.DBusBusType busType;
@ -89,7 +92,7 @@ public class DaemonCommand implements MultiLocalCommand {
var receiveThreads = new ArrayList<Thread>(); var receiveThreads = new ArrayList<Thread>();
for (var m : managers) { for (var m : managers) {
var objectPath = DbusConfig.getObjectPath(m.getUsername()); var objectPath = DbusConfig.getObjectPath(m.getUsername());
var thread = run(conn, objectPath, m, ignoreAttachments, inJson); var thread = run(conn, objectPath, m, ignoreAttachments);
receiveThreads.add(thread); receiveThreads.add(thread);
} }
@ -108,20 +111,17 @@ public class DaemonCommand implements MultiLocalCommand {
} }
private Thread run( private Thread run(
DBusConnection conn, String objectPath, Manager m, boolean ignoreAttachments, boolean inJson DBusConnection conn, String objectPath, Manager m, boolean ignoreAttachments
) throws DBusException { ) throws DBusException {
conn.exportObject(objectPath, new DbusSignalImpl(m)); conn.exportObject(objectPath, new DbusSignalImpl(m));
final var thread = new Thread(() -> { final var thread = new Thread(() -> {
while (true) { while (true) {
try { try {
m.receiveMessages(1, final var receiveMessageHandler = outputWriter instanceof JsonWriter
TimeUnit.HOURS, ? new JsonDbusReceiveMessageHandler(m, (JsonWriter) outputWriter, conn, objectPath)
false, : new DbusReceiveMessageHandler(m, (PlainTextWriter) outputWriter, conn, objectPath);
ignoreAttachments, m.receiveMessages(1, TimeUnit.HOURS, false, ignoreAttachments, receiveMessageHandler);
inJson
? new JsonDbusReceiveMessageHandler(m, conn, objectPath)
: new DbusReceiveMessageHandler(m, conn, objectPath));
} catch (IOException e) { } catch (IOException e) {
logger.warn("Receiving messages failed, retrying", e); logger.warn("Receiving messages failed, retrying", e);
} }

View file

@ -5,6 +5,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.JsonWriter; import org.asamk.signal.JsonWriter;
import org.asamk.signal.OutputType; import org.asamk.signal.OutputType;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
@ -21,13 +22,17 @@ import java.util.stream.Collectors;
public class GetUserStatusCommand implements LocalCommand { public class GetUserStatusCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(GetUserStatusCommand.class); private final static Logger logger = LoggerFactory.getLogger(GetUserStatusCommand.class);
private final OutputWriter outputWriter;
@Override public static void attachToSubparser(final Subparser subparser) {
public void attachToSubparser(final Subparser subparser) {
subparser.help("Check if the specified phone number/s have been registered"); subparser.help("Check if the specified phone number/s have been registered");
subparser.addArgument("number").help("Phone number").nargs("+"); subparser.addArgument("number").help("Phone number").nargs("+");
} }
public GetUserStatusCommand(final OutputWriter outputWriter) {
this.outputWriter = outputWriter;
}
@Override @Override
public Set<OutputType> getSupportedOutputTypes() { public Set<OutputType> getSupportedOutputTypes() {
return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON); return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON);
@ -35,9 +40,6 @@ public class GetUserStatusCommand implements LocalCommand {
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
// Setup the json object mapper
var inJson = ns.get("output") == OutputType.JSON;
// Get a map of registration statuses // Get a map of registration statuses
Map<String, Boolean> registered; Map<String, Boolean> registered;
try { try {
@ -48,8 +50,8 @@ public class GetUserStatusCommand implements LocalCommand {
} }
// Output // Output
if (inJson) { if (outputWriter instanceof JsonWriter) {
final var jsonWriter = new JsonWriter(System.out); final var jsonWriter = (JsonWriter) outputWriter;
var jsonUserStatuses = registered.entrySet() var jsonUserStatuses = registered.entrySet()
.stream() .stream()
@ -58,7 +60,7 @@ public class GetUserStatusCommand implements LocalCommand {
jsonWriter.write(jsonUserStatuses); jsonWriter.write(jsonUserStatuses);
} else { } else {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
for (var entry : registered.entrySet()) { for (var entry : registered.entrySet()) {
writer.println("{}: {}", entry.getKey(), entry.getValue()); writer.println("{}: {}", entry.getKey(), entry.getValue());

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
@ -20,8 +21,13 @@ import static org.asamk.signal.util.ErrorUtils.handleTimestampAndSendMessageResu
public class JoinGroupCommand implements LocalCommand { public class JoinGroupCommand implements LocalCommand {
@Override private final OutputWriter outputWriter;
public void attachToSubparser(final Subparser subparser) {
public JoinGroupCommand(final OutputWriter outputWriter) {
this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Join a group via an invitation link."); subparser.help("Join a group via an invitation link.");
subparser.addArgument("--uri").required(true).help("Specify the uri with the group invitation link."); subparser.addArgument("--uri").required(true).help("Specify the uri with the group invitation link.");
} }
@ -43,7 +49,7 @@ public class JoinGroupCommand implements LocalCommand {
} }
try { try {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
final var results = m.joinGroup(linkUrl); final var results = m.joinGroup(linkUrl);
var newGroupId = results.first(); var newGroupId = results.first();

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
@ -18,16 +19,20 @@ import java.util.concurrent.TimeoutException;
public class LinkCommand implements ProvisioningCommand { public class LinkCommand implements ProvisioningCommand {
private final static Logger logger = LoggerFactory.getLogger(LinkCommand.class); private final static Logger logger = LoggerFactory.getLogger(LinkCommand.class);
private final OutputWriter outputWriter;
@Override public LinkCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Link to an existing device, instead of registering a new number."); subparser.help("Link to an existing device, instead of registering a new number.");
subparser.addArgument("-n", "--name").help("Specify a name to describe this new device."); subparser.addArgument("-n", "--name").help("Specify a name to describe this new device.");
} }
@Override @Override
public void handleCommand(final Namespace ns, final ProvisioningManager m) throws CommandException { public void handleCommand(final Namespace ns, final ProvisioningManager m) throws CommandException {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
var deviceName = ns.getString("name"); var deviceName = ns.getString("name");
if (deviceName == null) { if (deviceName == null) {

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -10,14 +11,19 @@ import static org.asamk.signal.util.Util.getLegacyIdentifier;
public class ListContactsCommand implements LocalCommand { public class ListContactsCommand implements LocalCommand {
@Override private final OutputWriter outputWriter;
public void attachToSubparser(final Subparser subparser) {
public ListContactsCommand(final OutputWriter outputWriter) {
this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Show a list of known contacts with names."); subparser.help("Show a list of known contacts with names.");
} }
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) { public void handleCommand(final Namespace ns, final Manager m) {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
var contacts = m.getContacts(); var contacts = m.getContacts();
for (var c : contacts) { for (var c : contacts) {

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
@ -18,15 +19,19 @@ import java.util.List;
public class ListDevicesCommand implements LocalCommand { public class ListDevicesCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(ListDevicesCommand.class); private final static Logger logger = LoggerFactory.getLogger(ListDevicesCommand.class);
private final OutputWriter outputWriter;
@Override public ListDevicesCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Show a list of linked devices."); subparser.help("Show a list of linked devices.");
} }
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
List<Device> devices; List<Device> devices;
try { try {

View file

@ -6,8 +6,8 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.JsonWriter; import org.asamk.signal.JsonWriter;
import org.asamk.signal.OutputType; import org.asamk.signal.OutputType;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriter; import org.asamk.signal.PlainTextWriter;
import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
import org.asamk.signal.manager.storage.groups.GroupInfo; import org.asamk.signal.manager.storage.groups.GroupInfo;
@ -16,7 +16,6 @@ import org.asamk.signal.util.Util;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -24,6 +23,13 @@ public class ListGroupsCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(ListGroupsCommand.class); private final static Logger logger = LoggerFactory.getLogger(ListGroupsCommand.class);
public static void attachToSubparser(final Subparser subparser) {
subparser.help("List group information including names, ids, active status, blocked status and members");
subparser.addArgument("-d", "--detailed")
.action(Arguments.storeTrue())
.help("List the members and group invite links of each group. If output=json, then this is always set");
}
private static Set<String> resolveMembers(Manager m, Set<RecipientId> addresses) { private static Set<String> resolveMembers(Manager m, Set<RecipientId> addresses) {
return addresses.stream() return addresses.stream()
.map(m::resolveSignalServiceAddress) .map(m::resolveSignalServiceAddress)
@ -58,12 +64,10 @@ public class ListGroupsCommand implements LocalCommand {
} }
} }
@Override private final OutputWriter outputWriter;
public void attachToSubparser(final Subparser subparser) {
subparser.help("List group information including names, ids, active status, blocked status and members"); public ListGroupsCommand(final OutputWriter outputWriter) {
subparser.addArgument("-d", "--detailed") this.outputWriter = outputWriter;
.action(Arguments.storeTrue())
.help("List the members and group invite links of each group. If output=json, then this is always set");
} }
@Override @Override
@ -73,14 +77,15 @@ public class ListGroupsCommand implements LocalCommand {
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
if (ns.get("output") == OutputType.JSON) { final var groups = m.getGroups();
final var jsonWriter = new JsonWriter(System.out);
var jsonGroups = new ArrayList<JsonGroup>(); if (outputWriter instanceof JsonWriter) {
for (var group : m.getGroups()) { final var jsonWriter = (JsonWriter) outputWriter;
var jsonGroups = groups.stream().map(group -> {
final var groupInviteLink = group.getGroupInviteLink(); final var groupInviteLink = group.getGroupInviteLink();
jsonGroups.add(new JsonGroup(group.getGroupId().toBase64(), return new JsonGroup(group.getGroupId().toBase64(),
group.getTitle(), group.getTitle(),
group.getDescription(), group.getDescription(),
group.isMember(m.getSelfRecipientId()), group.isMember(m.getSelfRecipientId()),
@ -89,14 +94,14 @@ public class ListGroupsCommand implements LocalCommand {
resolveMembers(m, group.getPendingMembers()), resolveMembers(m, group.getPendingMembers()),
resolveMembers(m, group.getRequestingMembers()), resolveMembers(m, group.getRequestingMembers()),
resolveMembers(m, group.getAdminMembers()), resolveMembers(m, group.getAdminMembers()),
groupInviteLink == null ? null : groupInviteLink.getUrl())); groupInviteLink == null ? null : groupInviteLink.getUrl());
} }).collect(Collectors.toList());
jsonWriter.write(jsonGroups); jsonWriter.write(jsonGroups);
} else { } else {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriter) outputWriter;
boolean detailed = ns.getBoolean("detailed"); boolean detailed = ns.getBoolean("detailed");
for (var group : m.getGroups()) { for (var group : groups) {
printGroupPlainText(writer, m, group, detailed); printGroupPlainText(writer, m, group, detailed);
} }
} }

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriter; import org.asamk.signal.PlainTextWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
@ -21,6 +22,11 @@ import java.util.List;
public class ListIdentitiesCommand implements LocalCommand { public class ListIdentitiesCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(ListIdentitiesCommand.class); private final static Logger logger = LoggerFactory.getLogger(ListIdentitiesCommand.class);
private final OutputWriter outputWriter;
public ListIdentitiesCommand(final OutputWriter outputWriter) {
this.outputWriter = outputWriter;
}
private static void printIdentityFingerprint(PlainTextWriter writer, Manager m, IdentityInfo theirId) { private static void printIdentityFingerprint(PlainTextWriter writer, Manager m, IdentityInfo theirId) {
final SignalServiceAddress address = m.resolveSignalServiceAddress(theirId.getRecipientId()); final SignalServiceAddress address = m.resolveSignalServiceAddress(theirId.getRecipientId());
@ -33,15 +39,14 @@ public class ListIdentitiesCommand implements LocalCommand {
digits); digits);
} }
@Override public static void attachToSubparser(final Subparser subparser) {
public void attachToSubparser(final Subparser subparser) {
subparser.help("List all known identity keys and their trust status, fingerprint and safety number."); subparser.help("List all known identity keys and their trust status, fingerprint and safety number.");
subparser.addArgument("-n", "--number").help("Only show identity keys for the given phone number."); subparser.addArgument("-n", "--number").help("Only show identity keys for the given phone number.");
} }
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
var number = ns.getString("number"); var number = ns.getString("number");

View file

@ -4,6 +4,7 @@ import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
@ -28,9 +29,13 @@ import static org.asamk.signal.util.ErrorUtils.handleTimestampAndSendMessageResu
public class QuitGroupCommand implements LocalCommand { public class QuitGroupCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(QuitGroupCommand.class); private final static Logger logger = LoggerFactory.getLogger(QuitGroupCommand.class);
private final OutputWriter outputWriter;
@Override public QuitGroupCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Send a quit group message to all group members and remove self from member list."); subparser.help("Send a quit group message to all group members and remove self from member list.");
subparser.addArgument("-g", "--group").required(true).help("Specify the recipient group ID."); subparser.addArgument("-g", "--group").required(true).help("Specify the recipient group ID.");
subparser.addArgument("--delete") subparser.addArgument("--delete")
@ -43,7 +48,7 @@ public class QuitGroupCommand implements LocalCommand {
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
final GroupId groupId; final GroupId groupId;
try { try {

View file

@ -8,6 +8,8 @@ import org.asamk.Signal;
import org.asamk.signal.JsonReceiveMessageHandler; import org.asamk.signal.JsonReceiveMessageHandler;
import org.asamk.signal.JsonWriter; import org.asamk.signal.JsonWriter;
import org.asamk.signal.OutputType; import org.asamk.signal.OutputType;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.ReceiveMessageHandler; import org.asamk.signal.ReceiveMessageHandler;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
@ -30,9 +32,9 @@ import java.util.concurrent.TimeUnit;
public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand { public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(ReceiveCommand.class); private final static Logger logger = LoggerFactory.getLogger(ReceiveCommand.class);
private final OutputWriter outputWriter;
@Override public static void attachToSubparser(final Subparser subparser) {
public void attachToSubparser(final Subparser subparser) {
subparser.help("Query the server for new messages."); subparser.help("Query the server for new messages.");
subparser.addArgument("-t", "--timeout") subparser.addArgument("-t", "--timeout")
.type(double.class) .type(double.class)
@ -43,6 +45,10 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
.action(Arguments.storeTrue()); .action(Arguments.storeTrue());
} }
public ReceiveCommand(final OutputWriter outputWriter) {
this.outputWriter = outputWriter;
}
@Override @Override
public Set<OutputType> getSupportedOutputTypes() { public Set<OutputType> getSupportedOutputTypes() {
return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON); return Set.of(OutputType.PLAIN_TEXT, OutputType.JSON);
@ -51,11 +57,9 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
public void handleCommand( public void handleCommand(
final Namespace ns, final Signal signal, DBusConnection dbusconnection final Namespace ns, final Signal signal, DBusConnection dbusconnection
) throws CommandException { ) throws CommandException {
var inJson = ns.get("output") == OutputType.JSON;
try { try {
if (inJson) { if (outputWriter instanceof JsonWriter) {
final var jsonWriter = new JsonWriter(System.out); final var jsonWriter = (JsonWriter) outputWriter;
dbusconnection.addSigHandler(Signal.MessageReceived.class, signal, messageReceived -> { dbusconnection.addSigHandler(Signal.MessageReceived.class, signal, messageReceived -> {
var envelope = new JsonMessageEnvelope(messageReceived); var envelope = new JsonMessageEnvelope(messageReceived);
@ -75,7 +79,7 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
jsonWriter.write(object); jsonWriter.write(object);
}); });
} else { } else {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
dbusconnection.addSigHandler(Signal.MessageReceived.class, signal, messageReceived -> { dbusconnection.addSigHandler(Signal.MessageReceived.class, signal, messageReceived -> {
writer.println("Envelope from: {}", messageReceived.getSender()); writer.println("Envelope from: {}", messageReceived.getSender());
@ -135,8 +139,6 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
var inJson = ns.get("output") == OutputType.JSON;
double timeout = ns.getDouble("timeout"); double timeout = ns.getDouble("timeout");
var returnOnTimeout = true; var returnOnTimeout = true;
if (timeout < 0) { if (timeout < 0) {
@ -145,7 +147,8 @@ public class ReceiveCommand implements ExtendedDbusCommand, LocalCommand {
} }
boolean ignoreAttachments = ns.getBoolean("ignore-attachments"); boolean ignoreAttachments = ns.getBoolean("ignore-attachments");
try { try {
final var handler = inJson ? new JsonReceiveMessageHandler(m) : new ReceiveMessageHandler(m); final var handler = outputWriter instanceof JsonWriter ? new JsonReceiveMessageHandler(m,
(JsonWriter) outputWriter) : new ReceiveMessageHandler(m, (PlainTextWriter) outputWriter);
m.receiveMessages((long) (timeout * 1000), m.receiveMessages((long) (timeout * 1000),
TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS,
returnOnTimeout, returnOnTimeout,

View file

@ -4,6 +4,7 @@ import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.commands.exceptions.UserErrorException;
@ -14,8 +15,10 @@ import java.io.IOException;
public class RegisterCommand implements RegistrationCommand { public class RegisterCommand implements RegistrationCommand {
@Override public RegisterCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Register a phone number with SMS or voice verification."); subparser.help("Register a phone number with SMS or voice verification.");
subparser.addArgument("-v", "--voice") subparser.addArgument("-v", "--voice")
.help("The verification should be done over voice, not SMS.") .help("The verification should be done over voice, not SMS.")

View file

@ -4,6 +4,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.Signal; import org.asamk.Signal;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@ -17,8 +18,13 @@ import java.util.List;
public class RemoteDeleteCommand implements DbusCommand { public class RemoteDeleteCommand implements DbusCommand {
@Override private final OutputWriter outputWriter;
public void attachToSubparser(final Subparser subparser) {
public RemoteDeleteCommand(final OutputWriter outputWriter) {
this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Remotely delete a previously sent message."); subparser.help("Remotely delete a previously sent message.");
subparser.addArgument("-t", "--target-timestamp") subparser.addArgument("-t", "--target-timestamp")
.required(true) .required(true)
@ -43,7 +49,7 @@ public class RemoteDeleteCommand implements DbusCommand {
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; byte[] groupId = null;
if (groupIdString != null) { if (groupIdString != null) {

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -11,8 +12,10 @@ import java.io.IOException;
public class RemoveDeviceCommand implements LocalCommand { public class RemoveDeviceCommand implements LocalCommand {
@Override public RemoveDeviceCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Remove a linked device."); subparser.help("Remove a linked device.");
subparser.addArgument("-d", "--device-id", "--deviceId") subparser.addArgument("-d", "--device-id", "--deviceId")
.type(int.class) .type(int.class)

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@ -14,8 +15,10 @@ import java.io.IOException;
public class RemovePinCommand implements LocalCommand { public class RemovePinCommand implements LocalCommand {
@Override public RemovePinCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Remove the registration lock pin."); subparser.help("Remove the registration lock pin.");
} }

View file

@ -5,6 +5,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.Signal; import org.asamk.Signal;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@ -25,9 +26,13 @@ import java.util.List;
public class SendCommand implements DbusCommand { public class SendCommand implements DbusCommand {
private final static Logger logger = LoggerFactory.getLogger(SendCommand.class); private final static Logger logger = LoggerFactory.getLogger(SendCommand.class);
private final OutputWriter outputWriter;
@Override public SendCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Send a message to another user or group."); subparser.help("Send a message to another user or group.");
subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*"); subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
final var mutuallyExclusiveGroup = subparser.addMutuallyExclusiveGroup(); final var mutuallyExclusiveGroup = subparser.addMutuallyExclusiveGroup();
@ -87,7 +92,7 @@ public class SendCommand implements DbusCommand {
attachments = List.of(); attachments = List.of();
} }
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
if (groupIdString != null) { if (groupIdString != null) {
byte[] groupId; byte[] groupId;

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException; import org.asamk.signal.commands.exceptions.UntrustedKeyErrorException;
@ -13,8 +14,10 @@ import java.io.IOException;
public class SendContactsCommand implements LocalCommand { public class SendContactsCommand implements LocalCommand {
@Override public SendContactsCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Send a synchronization message with the local contacts list to all linked devices."); subparser.help("Send a synchronization message with the local contacts list to all linked devices.");
} }

View file

@ -5,6 +5,7 @@ import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.Signal; import org.asamk.Signal;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@ -18,8 +19,13 @@ import java.util.List;
public class SendReactionCommand implements DbusCommand { public class SendReactionCommand implements DbusCommand {
@Override private final OutputWriter outputWriter;
public void attachToSubparser(final Subparser subparser) {
public SendReactionCommand(final OutputWriter outputWriter) {
this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Send reaction to a previously received or sent message."); subparser.help("Send reaction to a previously received or sent message.");
subparser.addArgument("-g", "--group").help("Specify the recipient group ID."); subparser.addArgument("-g", "--group").help("Specify the recipient group ID.");
subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*"); subparser.addArgument("recipient").help("Specify the recipients' phone number.").nargs("*");
@ -54,7 +60,7 @@ public class SendReactionCommand implements DbusCommand {
final var targetAuthor = ns.getString("target-author"); final var targetAuthor = ns.getString("target-author");
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; byte[] groupId = null;
if (groupIdString != null) { if (groupIdString != null) {

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -11,8 +12,10 @@ import java.io.IOException;
public class SendSyncRequestCommand implements LocalCommand { public class SendSyncRequestCommand implements LocalCommand {
@Override public SendSyncRequestCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Send a synchronization request message to master device (for group, contacts, ...)."); subparser.help("Send a synchronization request message to master device (for group, contacts, ...).");
} }

View file

@ -4,6 +4,7 @@ import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -21,8 +22,10 @@ import java.util.HashSet;
public class SendTypingCommand implements LocalCommand { public class SendTypingCommand implements LocalCommand {
@Override public SendTypingCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help( subparser.help(
"Send typing message to trigger a typing indicator for the recipient. Indicator will be shown for 15seconds unless a typing STOP message is sent first."); "Send typing message to trigger a typing indicator for the recipient. Indicator will be shown for 15seconds unless a typing STOP message is sent first.");
subparser.addArgument("-g", "--group").help("Specify the recipient group ID."); subparser.addArgument("-g", "--group").help("Specify the recipient group ID.");

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@ -14,8 +15,10 @@ import java.io.IOException;
public class SetPinCommand implements LocalCommand { public class SetPinCommand implements LocalCommand {
@Override public SetPinCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Set a registration lock pin, to prevent others from registering this number."); subparser.help("Set a registration lock pin, to prevent others from registering this number.");
subparser.addArgument("registrationLockPin") subparser.addArgument("registrationLockPin")
.help("The registration lock PIN, that will be required for new registrations (resets after 7 days of inactivity)"); .help("The registration lock PIN, that will be required for new registrations (resets after 7 days of inactivity)");

View file

@ -0,0 +1,8 @@
package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Subparser;
public interface SubparserAttacher {
void attachToSubparser(final Subparser subparser);
}

View file

@ -4,6 +4,7 @@ import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -14,8 +15,10 @@ import java.util.Locale;
public class TrustCommand implements LocalCommand { public class TrustCommand implements LocalCommand {
@Override public TrustCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Set the trust level of a given number."); subparser.help("Set the trust level of a given number.");
subparser.addArgument("number").help("Specify the phone number, for which to set the trust.").required(true); subparser.addArgument("number").help("Specify the phone number, for which to set the trust.").required(true);
var mutTrust = subparser.addMutuallyExclusiveGroup(); var mutTrust = subparser.addMutuallyExclusiveGroup();

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.commands.exceptions.UserErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -18,8 +19,10 @@ public class UnblockCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(UnblockCommand.class); private final static Logger logger = LoggerFactory.getLogger(UnblockCommand.class);
@Override public UnblockCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Unblock the given contacts or groups (messages will be received again)"); subparser.help("Unblock the given contacts or groups (messages will be received again)");
subparser.addArgument("contact").help("Contact number").nargs("*"); subparser.addArgument("contact").help("Contact number").nargs("*");
subparser.addArgument("-g", "--group").help("Group ID").nargs("*"); subparser.addArgument("-g", "--group").help("Group ID").nargs("*");

View file

@ -4,6 +4,7 @@ import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -12,8 +13,10 @@ import java.io.IOException;
public class UnregisterCommand implements LocalCommand { public class UnregisterCommand implements LocalCommand {
@Override public UnregisterCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Unregister the current device from the signal server."); subparser.help("Unregister the current device from the signal server.");
subparser.addArgument("--delete-account") subparser.addArgument("--delete-account")
.help("Delete account completely from server. CAUTION: Only do this if you won't use this number again!") .help("Delete account completely from server. CAUTION: Only do this if you won't use this number again!")

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -11,8 +12,10 @@ import java.io.IOException;
public class UpdateAccountCommand implements LocalCommand { public class UpdateAccountCommand implements LocalCommand {
@Override public UpdateAccountCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Update the account attributes on the signal server."); subparser.help("Update the account attributes on the signal server.");
} }

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UserErrorException; import org.asamk.signal.commands.exceptions.UserErrorException;
@ -14,8 +15,10 @@ import java.io.IOException;
public class UpdateContactCommand implements LocalCommand { public class UpdateContactCommand implements LocalCommand {
@Override public UpdateContactCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Update the details of a given contact"); subparser.help("Update the details of a given contact");
subparser.addArgument("number").help("Contact number"); subparser.addArgument("number").help("Contact number");
subparser.addArgument("-n", "--name").help("New contact name"); subparser.addArgument("-n", "--name").help("New contact name");

View file

@ -7,6 +7,7 @@ import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.Signal; import org.asamk.Signal;
import org.asamk.signal.GroupLinkState; import org.asamk.signal.GroupLinkState;
import org.asamk.signal.GroupPermission; import org.asamk.signal.GroupPermission;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@ -33,9 +34,13 @@ import java.util.List;
public class UpdateGroupCommand implements DbusCommand, LocalCommand { public class UpdateGroupCommand implements DbusCommand, LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(UpdateGroupCommand.class); private final static Logger logger = LoggerFactory.getLogger(UpdateGroupCommand.class);
private final OutputWriter outputWriter;
@Override public UpdateGroupCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Create or update a group."); subparser.help("Create or update a group.");
subparser.addArgument("-g", "--group").help("Specify the recipient group ID."); subparser.addArgument("-g", "--group").help("Specify the recipient group ID.");
subparser.addArgument("-n", "--name").help("Specify the new group name."); subparser.addArgument("-n", "--name").help("Specify the new group name.");
@ -69,7 +74,7 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
GroupId groupId = null; GroupId groupId = null;
final var groupIdString = ns.getString("group"); final var groupIdString = ns.getString("group");
if (groupIdString != null) { if (groupIdString != null) {
@ -137,7 +142,7 @@ public class UpdateGroupCommand implements DbusCommand, LocalCommand {
@Override @Override
public void handleCommand(final Namespace ns, final Signal signal) throws CommandException { public void handleCommand(final Namespace ns, final Signal signal) throws CommandException {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
byte[] groupId = null; byte[] groupId = null;
if (ns.getString("group") != null) { if (ns.getString("group") != null) {
try { try {

View file

@ -4,6 +4,7 @@ import net.sourceforge.argparse4j.impl.Arguments;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.manager.Manager; import org.asamk.signal.manager.Manager;
@ -14,8 +15,10 @@ import java.io.IOException;
public class UpdateProfileCommand implements LocalCommand { public class UpdateProfileCommand implements LocalCommand {
@Override public UpdateProfileCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Set a name, about and avatar image for the user profile"); subparser.help("Set a name, about and avatar image for the user profile");
subparser.addArgument("--given-name", "--name").help("New profile (given) name"); subparser.addArgument("--given-name", "--name").help("New profile (given) name");
subparser.addArgument("--family-name").help("New profile family name (optional)"); subparser.addArgument("--family-name").help("New profile family name (optional)");

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.PlainTextWriterImpl; import org.asamk.signal.PlainTextWriterImpl;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
@ -18,9 +19,13 @@ import java.io.IOException;
public class UploadStickerPackCommand implements LocalCommand { public class UploadStickerPackCommand implements LocalCommand {
private final static Logger logger = LoggerFactory.getLogger(UploadStickerPackCommand.class); private final static Logger logger = LoggerFactory.getLogger(UploadStickerPackCommand.class);
private final OutputWriter outputWriter;
@Override public UploadStickerPackCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { this.outputWriter = outputWriter;
}
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Upload a new sticker pack, consisting of a manifest file and the stickers images."); subparser.help("Upload a new sticker pack, consisting of a manifest file and the stickers images.");
subparser.addArgument("path") subparser.addArgument("path")
.help("The path of the manifest.json or a zip file containing the sticker pack you wish to upload."); .help("The path of the manifest.json or a zip file containing the sticker pack you wish to upload.");
@ -28,7 +33,7 @@ public class UploadStickerPackCommand implements LocalCommand {
@Override @Override
public void handleCommand(final Namespace ns, final Manager m) throws CommandException { public void handleCommand(final Namespace ns, final Manager m) throws CommandException {
final var writer = new PlainTextWriterImpl(System.out); final var writer = (PlainTextWriterImpl) outputWriter;
var path = new File(ns.getString("path")); var path = new File(ns.getString("path"));
try { try {

View file

@ -3,6 +3,7 @@ package org.asamk.signal.commands;
import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Namespace;
import net.sourceforge.argparse4j.inf.Subparser; import net.sourceforge.argparse4j.inf.Subparser;
import org.asamk.signal.OutputWriter;
import org.asamk.signal.commands.exceptions.CommandException; import org.asamk.signal.commands.exceptions.CommandException;
import org.asamk.signal.commands.exceptions.IOErrorException; import org.asamk.signal.commands.exceptions.IOErrorException;
import org.asamk.signal.commands.exceptions.UnexpectedErrorException; import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
@ -16,8 +17,10 @@ import java.io.IOException;
public class VerifyCommand implements RegistrationCommand { public class VerifyCommand implements RegistrationCommand {
@Override public VerifyCommand(final OutputWriter outputWriter) {
public void attachToSubparser(final Subparser subparser) { }
public static void attachToSubparser(final Subparser subparser) {
subparser.help("Verify the number using the code received via SMS or voice."); subparser.help("Verify the number using the code received via SMS or voice.");
subparser.addArgument("verificationCode").help("The verification code you received via sms or voice call."); subparser.addArgument("verificationCode").help("The verification code you received via sms or voice call.");
subparser.addArgument("-p", "--pin").help("The registration lock PIN, that was set by the user (Optional)"); subparser.addArgument("-p", "--pin").help("The registration lock PIN, that was set by the user (Optional)");