]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/Commands.java
fix
[signal-cli] / src / main / java / org / asamk / signal / commands / Commands.java
1 package org.asamk.signal.commands;
2
3 import org.asamk.signal.OutputWriter;
4
5 import java.util.HashMap;
6 import java.util.Map;
7 import java.util.TreeMap;
8
9 public class Commands {
10
11 private static final Map<String, CommandConstructor> commands = new HashMap<>();
12 private static final Map<String, SubparserAttacher> commandSubparserAttacher = new TreeMap<>();
13
14 static {
15 addCommand("addDevice", AddDeviceCommand::new, AddDeviceCommand::attachToSubparser);
16 addCommand("block", BlockCommand::new, BlockCommand::attachToSubparser);
17 addCommand("daemon", DaemonCommand::new, DaemonCommand::attachToSubparser);
18 addCommand("getUserStatus", GetUserStatusCommand::new, GetUserStatusCommand::attachToSubparser);
19 addCommand("jsonRpc", JsonRpcDispatcherCommand::new, JsonRpcDispatcherCommand::attachToSubparser);
20 addCommand("link", LinkCommand::new, LinkCommand::attachToSubparser);
21 addCommand("listContacts", ListContactsCommand::new, ListContactsCommand::attachToSubparser);
22 addCommand("listDevices", ListDevicesCommand::new, ListDevicesCommand::attachToSubparser);
23 addCommand("listGroups", ListGroupsCommand::new, ListGroupsCommand::attachToSubparser);
24 addCommand("listIdentities", ListIdentitiesCommand::new, ListIdentitiesCommand::attachToSubparser);
25 addCommand("joinGroup", JoinGroupCommand::new, JoinGroupCommand::attachToSubparser);
26 addCommand("quitGroup", QuitGroupCommand::new, QuitGroupCommand::attachToSubparser);
27 addCommand("receive", ReceiveCommand::new, ReceiveCommand::attachToSubparser);
28 addCommand("register", RegisterCommand::new, RegisterCommand::attachToSubparser);
29 addCommand("removeDevice", RemoveDeviceCommand::new, RemoveDeviceCommand::attachToSubparser);
30 addCommand("remoteDelete", RemoteDeleteCommand::new, RemoteDeleteCommand::attachToSubparser);
31 addCommand("removePin", RemovePinCommand::new, RemovePinCommand::attachToSubparser);
32 addCommand("send", SendCommand::new, SendCommand::attachToSubparser);
33 addCommand("sendContacts", SendContactsCommand::new, SendContactsCommand::attachToSubparser);
34 addCommand("sendReaction", SendReactionCommand::new, SendReactionCommand::attachToSubparser);
35 addCommand("sendSyncRequest", SendSyncRequestCommand::new, SendSyncRequestCommand::attachToSubparser);
36 addCommand("sendTyping", SendTypingCommand::new, SendTypingCommand::attachToSubparser);
37 addCommand("setPin", SetPinCommand::new, SetPinCommand::attachToSubparser);
38 addCommand("trust", TrustCommand::new, TrustCommand::attachToSubparser);
39 addCommand("unblock", UnblockCommand::new, UnblockCommand::attachToSubparser);
40 addCommand("unregister", UnregisterCommand::new, UnregisterCommand::attachToSubparser);
41 addCommand("updateAccount", UpdateAccountCommand::new, UpdateAccountCommand::attachToSubparser);
42 addCommand("updateContact", UpdateContactCommand::new, UpdateContactCommand::attachToSubparser);
43 addCommand("updateGroup", UpdateGroupCommand::new, UpdateGroupCommand::attachToSubparser);
44 addCommand("updateProfile", UpdateProfileCommand::new, UpdateProfileCommand::attachToSubparser);
45 addCommand("uploadStickerPack", UploadStickerPackCommand::new, UploadStickerPackCommand::attachToSubparser);
46 addCommand("verify", VerifyCommand::new, VerifyCommand::attachToSubparser);
47 addCommand("version", VersionCommand::new, null);
48 }
49
50 public static Map<String, SubparserAttacher> getCommandSubparserAttachers() {
51 return commandSubparserAttacher;
52 }
53
54 public static Command getCommand(String commandKey, OutputWriter outputWriter) {
55 if (!commands.containsKey(commandKey)) {
56 return null;
57 }
58 return commands.get(commandKey).constructCommand(outputWriter);
59 }
60
61 private static void addCommand(
62 String name, CommandConstructor commandConstructor, SubparserAttacher subparserAttacher
63 ) {
64 commands.put(name, commandConstructor);
65 if (subparserAttacher != null) {
66 commandSubparserAttacher.put(name, subparserAttacher);
67 }
68 }
69
70 private interface CommandConstructor {
71
72 Command constructCommand(OutputWriter outputWriter);
73 }
74 }