mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 18:40:39 +00:00
Refactor output writers
This commit is contained in:
parent
f449a242e4
commit
48b2c7ff8a
42 changed files with 327 additions and 187 deletions
|
@ -1,58 +1,70 @@
|
|||
package org.asamk.signal.commands;
|
||||
|
||||
import org.asamk.signal.OutputWriter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
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 {
|
||||
addCommand("addDevice", new AddDeviceCommand());
|
||||
addCommand("block", new BlockCommand());
|
||||
addCommand("daemon", new DaemonCommand());
|
||||
addCommand("getUserStatus", new GetUserStatusCommand());
|
||||
addCommand("link", new LinkCommand());
|
||||
addCommand("listContacts", new ListContactsCommand());
|
||||
addCommand("listDevices", new ListDevicesCommand());
|
||||
addCommand("listGroups", new ListGroupsCommand());
|
||||
addCommand("listIdentities", new ListIdentitiesCommand());
|
||||
addCommand("joinGroup", new JoinGroupCommand());
|
||||
addCommand("quitGroup", new QuitGroupCommand());
|
||||
addCommand("receive", new ReceiveCommand());
|
||||
addCommand("register", new RegisterCommand());
|
||||
addCommand("removeDevice", new RemoveDeviceCommand());
|
||||
addCommand("remoteDelete", new RemoteDeleteCommand());
|
||||
addCommand("removePin", new RemovePinCommand());
|
||||
addCommand("send", new SendCommand());
|
||||
addCommand("sendContacts", new SendContactsCommand());
|
||||
addCommand("sendReaction", new SendReactionCommand());
|
||||
addCommand("sendSyncRequest", new SendSyncRequestCommand());
|
||||
addCommand("sendTyping", new SendTypingCommand());
|
||||
addCommand("setPin", new SetPinCommand());
|
||||
addCommand("trust", new TrustCommand());
|
||||
addCommand("unblock", new UnblockCommand());
|
||||
addCommand("unregister", new UnregisterCommand());
|
||||
addCommand("updateAccount", new UpdateAccountCommand());
|
||||
addCommand("updateContact", new UpdateContactCommand());
|
||||
addCommand("updateGroup", new UpdateGroupCommand());
|
||||
addCommand("updateProfile", new UpdateProfileCommand());
|
||||
addCommand("uploadStickerPack", new UploadStickerPackCommand());
|
||||
addCommand("verify", new VerifyCommand());
|
||||
addCommand("addDevice", AddDeviceCommand::new, AddDeviceCommand::attachToSubparser);
|
||||
addCommand("block", BlockCommand::new, BlockCommand::attachToSubparser);
|
||||
addCommand("daemon", DaemonCommand::new, DaemonCommand::attachToSubparser);
|
||||
addCommand("getUserStatus", GetUserStatusCommand::new, GetUserStatusCommand::attachToSubparser);
|
||||
addCommand("link", LinkCommand::new, LinkCommand::attachToSubparser);
|
||||
addCommand("listContacts", ListContactsCommand::new, ListContactsCommand::attachToSubparser);
|
||||
addCommand("listDevices", ListDevicesCommand::new, ListDevicesCommand::attachToSubparser);
|
||||
addCommand("listGroups", ListGroupsCommand::new, ListGroupsCommand::attachToSubparser);
|
||||
addCommand("listIdentities", ListIdentitiesCommand::new, ListIdentitiesCommand::attachToSubparser);
|
||||
addCommand("joinGroup", JoinGroupCommand::new, JoinGroupCommand::attachToSubparser);
|
||||
addCommand("quitGroup", QuitGroupCommand::new, QuitGroupCommand::attachToSubparser);
|
||||
addCommand("receive", ReceiveCommand::new, ReceiveCommand::attachToSubparser);
|
||||
addCommand("register", RegisterCommand::new, RegisterCommand::attachToSubparser);
|
||||
addCommand("removeDevice", RemoveDeviceCommand::new, RemoveDeviceCommand::attachToSubparser);
|
||||
addCommand("remoteDelete", RemoteDeleteCommand::new, RemoteDeleteCommand::attachToSubparser);
|
||||
addCommand("removePin", RemovePinCommand::new, RemovePinCommand::attachToSubparser);
|
||||
addCommand("send", SendCommand::new, SendCommand::attachToSubparser);
|
||||
addCommand("sendContacts", SendContactsCommand::new, SendContactsCommand::attachToSubparser);
|
||||
addCommand("sendReaction", SendReactionCommand::new, SendReactionCommand::attachToSubparser);
|
||||
addCommand("sendSyncRequest", SendSyncRequestCommand::new, SendSyncRequestCommand::attachToSubparser);
|
||||
addCommand("sendTyping", SendTypingCommand::new, SendTypingCommand::attachToSubparser);
|
||||
addCommand("setPin", SetPinCommand::new, SetPinCommand::attachToSubparser);
|
||||
addCommand("trust", TrustCommand::new, TrustCommand::attachToSubparser);
|
||||
addCommand("unblock", UnblockCommand::new, UnblockCommand::attachToSubparser);
|
||||
addCommand("unregister", UnregisterCommand::new, UnregisterCommand::attachToSubparser);
|
||||
addCommand("updateAccount", UpdateAccountCommand::new, UpdateAccountCommand::attachToSubparser);
|
||||
addCommand("updateContact", UpdateContactCommand::new, UpdateContactCommand::attachToSubparser);
|
||||
addCommand("updateGroup", UpdateGroupCommand::new, UpdateGroupCommand::attachToSubparser);
|
||||
addCommand("updateProfile", UpdateProfileCommand::new, UpdateProfileCommand::attachToSubparser);
|
||||
addCommand("uploadStickerPack", UploadStickerPackCommand::new, UploadStickerPackCommand::attachToSubparser);
|
||||
addCommand("verify", VerifyCommand::new, VerifyCommand::attachToSubparser);
|
||||
}
|
||||
|
||||
public static Map<String, Command> getCommands() {
|
||||
return commands;
|
||||
public static Map<String, SubparserAttacher> getCommandSubparserAttachers() {
|
||||
return commandSubparserAttacher;
|
||||
}
|
||||
|
||||
public static Command getCommand(String commandKey) {
|
||||
public static Command getCommand(String commandKey, OutputWriter outputWriter) {
|
||||
if (!commands.containsKey(commandKey)) {
|
||||
return null;
|
||||
}
|
||||
return commands.get(commandKey);
|
||||
return commands.get(commandKey).constructCommand(outputWriter);
|
||||
}
|
||||
|
||||
private static void addCommand(String name, Command command) {
|
||||
commands.put(name, command);
|
||||
private static void addCommand(
|
||||
String name, CommandConstructor commandConstructor, SubparserAttacher subparserAttacher
|
||||
) {
|
||||
commands.put(name, commandConstructor);
|
||||
commandSubparserAttacher.put(name, subparserAttacher);
|
||||
}
|
||||
|
||||
private interface CommandConstructor {
|
||||
|
||||
Command constructCommand(OutputWriter outputWriter);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue