|
1 | 1 | package org.quiltmc.enigma.command; |
2 | 2 |
|
| 3 | +import com.google.common.collect.ImmutableMap; |
3 | 4 | import org.quiltmc.enigma.api.Enigma; |
4 | 5 | import org.tinylog.Logger; |
5 | 6 |
|
6 | | -import java.util.LinkedHashMap; |
7 | 7 | import java.util.Locale; |
8 | 8 | import java.util.Map; |
| 9 | +import java.util.function.Function; |
| 10 | +import java.util.stream.Stream; |
| 11 | + |
| 12 | +import static com.google.common.collect.ImmutableMap.toImmutableMap; |
9 | 13 |
|
10 | 14 | public class Main { |
11 | | - private static final Map<String, Command> COMMANDS = new LinkedHashMap<>(); |
| 15 | + private static final ImmutableMap<String, Command> COMMANDS = Stream |
| 16 | + .of( |
| 17 | + DeobfuscateCommand.INSTANCE, |
| 18 | + DecompileCommand.INSTANCE, |
| 19 | + ConvertMappingsCommand.INSTANCE, |
| 20 | + ComposeMappingsCommand.INSTANCE, |
| 21 | + InvertMappingsCommand.INSTANCE, |
| 22 | + CheckMappingsCommand.INSTANCE, |
| 23 | + MapSpecializedMethodsCommand.INSTANCE, |
| 24 | + InsertProposedMappingsCommand.INSTANCE, |
| 25 | + DropInvalidMappingsCommand.INSTANCE, |
| 26 | + FillClassMappingsCommand.INSTANCE, |
| 27 | + HelpCommand.INSTANCE, |
| 28 | + PrintStatsCommand.INSTANCE |
| 29 | + ) |
| 30 | + .collect(toImmutableMap(Command::getName, Function.identity())); |
12 | 31 |
|
13 | 32 | public static void main(String... args) { |
14 | 33 | try { |
@@ -97,32 +116,10 @@ private static void appendHelp(Argument argument, int index, StringBuilder build |
97 | 116 | builder.append(argument.explanation()).append("\n"); |
98 | 117 | } |
99 | 118 |
|
100 | | - private static void register(Command command) { |
101 | | - Command old = COMMANDS.put(command.getName(), command); |
102 | | - if (old != null) { |
103 | | - Logger.warn("Command {} with name {} has been substituted by {}", old, command.getName(), command); |
104 | | - } |
105 | | - } |
106 | | - |
107 | 119 | private static void logEnigmaInfo() { |
108 | 120 | Logger.info("{} - {}", Enigma.NAME, Enigma.VERSION); |
109 | 121 | } |
110 | 122 |
|
111 | | - static { |
112 | | - register(DeobfuscateCommand.INSTANCE); |
113 | | - register(DecompileCommand.INSTANCE); |
114 | | - register(ConvertMappingsCommand.INSTANCE); |
115 | | - register(ComposeMappingsCommand.INSTANCE); |
116 | | - register(InvertMappingsCommand.INSTANCE); |
117 | | - register(CheckMappingsCommand.INSTANCE); |
118 | | - register(MapSpecializedMethodsCommand.INSTANCE); |
119 | | - register(InsertProposedMappingsCommand.INSTANCE); |
120 | | - register(DropInvalidMappingsCommand.INSTANCE); |
121 | | - register(FillClassMappingsCommand.INSTANCE); |
122 | | - register(HelpCommand.INSTANCE); |
123 | | - register(PrintStatsCommand.INSTANCE); |
124 | | - } |
125 | | - |
126 | 123 | private static final class CommandHelpException extends IllegalArgumentException { |
127 | 124 | final Command command; |
128 | 125 |
|
|
0 commit comments