]> nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/commands/Commands.java
2e1d682181a3ae2c285791281cf23fa56153ed9e
[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("link", LinkCommand::new, LinkCommand::attachToSubparser);
20 addCommand("listContacts", ListContactsCommand::new, ListContactsCommand::attachToSubparser);
21 addCommand("listDevices", ListDevicesCommand::new, ListDevicesCommand::attachToSubparser);
22 addCommand("listGroups", ListGroupsCommand::new, ListGroupsCommand::attachToSubparser);
23 addCommand("listIdentities", ListIdentitiesCommand::new, ListIdentitiesCommand::attachToSubparser);
24 addCommand("joinGroup", JoinGroupCommand::new, JoinGroupCommand::attachToSubparser);
25 addCommand("quitGroup", QuitGroupCommand::new, QuitGroupCommand::attachToSubparser);
26 addCommand("receive", ReceiveCommand::new, ReceiveCommand::attachToSubparser);
27 addCommand("register", RegisterCommand::new, RegisterCommand::attachToSubparser);
28 addCommand("removeDevice", RemoveDeviceCommand::new, RemoveDeviceCommand::attachToSubparser);
29 addCommand("remoteDelete", RemoteDeleteCommand::new, RemoteDeleteCommand::attachToSubparser);
30 addCommand("removePin", RemovePinCommand::new, RemovePinCommand::attachToSubparser);
31 addCommand("send", SendCommand::new, SendCommand::attachToSubparser);
32 addCommand("sendContacts", SendContactsCommand::new, SendContactsCommand::attachToSubparser);
33 addCommand("sendReaction", SendReactionCommand::new, SendReactionCommand::attachToSubparser);
34 addCommand("sendSyncRequest", SendSyncRequestCommand::new, SendSyncRequestCommand::attachToSubparser);
35 addCommand("sendTyping", SendTypingCommand::new, SendTypingCommand::attachToSubparser);
36 addCommand("setPin", SetPinCommand::new, SetPinCommand::attachToSubparser);
37 addCommand("trust", TrustCommand::new, TrustCommand::attachToSubparser);
38 addCommand("unblock", UnblockCommand::new, UnblockCommand::attachToSubparser);
39 addCommand("unregister", UnregisterCommand::new, UnregisterCommand::attachToSubparser);
40 addCommand("updateAccount", UpdateAccountCommand::new, UpdateAccountCommand::attachToSubparser);
41 addCommand("updateContact", UpdateContactCommand::new, UpdateContactCommand::attachToSubparser);
42 addCommand("updateGroup", UpdateGroupCommand::new, UpdateGroupCommand::attachToSubparser);
43 addCommand("updateProfile", UpdateProfileCommand::new, UpdateProfileCommand::attachToSubparser);
44 addCommand("uploadStickerPack", UploadStickerPackCommand::new, UploadStickerPackCommand::attachToSubparser);
45 addCommand("verify", VerifyCommand::new, VerifyCommand::attachToSubparser);
46 }
47
48 public static Map<String, SubparserAttacher> getCommandSubparserAttachers() {
49 return commandSubparserAttacher;
50 }
51
52 public static Command getCommand(String commandKey, OutputWriter outputWriter) {
53 if (!commands.containsKey(commandKey)) {
54 return null;
55 }
56 return commands.get(commandKey).constructCommand(outputWriter);
57 }
58
59 private static void addCommand(
60 String name, CommandConstructor commandConstructor, SubparserAttacher subparserAttacher
61 ) {
62 commands.put(name, commandConstructor);
63 commandSubparserAttacher.put(name, subparserAttacher);
64 }
65
66 private interface CommandConstructor {
67
68 Command constructCommand(OutputWriter outputWriter);
69 }
70 }