Skip to content

Commit 64de20a

Browse files
committed
English Command Replaced With Language Command
You can now use `-language ger` or `-language de` to select languages
1 parent e6f9f16 commit 64de20a

5 files changed

Lines changed: 139 additions & 32 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/cli/BCVCommandLine.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.apache.commons.cli.*;
44
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
5-
import the.bytecode.club.bytecodeviewer.cli.actions.commands.HelpCommand;
5+
import the.bytecode.club.bytecodeviewer.cli.actions.commands.*;
66
import the.bytecode.club.bytecodeviewer.util.SleepUtil;
77

88
import java.io.File;
@@ -27,15 +27,19 @@ public void init(String[] args)
2727
OPTIONS.addOption("t", true, "sets the target class to decompile, append all to decomp all as zip.");
2828
OPTIONS.addOption("nowait", true, "won't wait the 5 seconds to allow the user to read the CLI.");
2929

30+
COMMANDS.add(new CleanCommand());
31+
COMMANDS.add(new CleanBootCommand());
32+
COMMANDS.add(new DecompilerCommand());
33+
COMMANDS.add(new LanguageCommand());
3034
COMMANDS.add(new HelpCommand());
35+
COMMANDS.add(new ListCommand());
3136

3237
for(CLICommand command : COMMANDS)
3338
OPTIONS.addOption(command.name, command.hasArgs, command.description);
3439

3540
isCLI = containsCLICommand(args);
3641

37-
if(isCLI)
38-
parseCommandLine(args);
42+
parseCommandLine(args);
3943
}
4044

4145
private boolean containsCLICommand(String[] args)
@@ -65,19 +69,25 @@ private void parseCommandLine(String[] args)
6569
{
6670
CommandLine cmd = PARSER.parse(OPTIONS, args);
6771

72+
if(cmd.hasOption("language"))
73+
System.out.println("OK: " + cmd.getOptionValue("language"));
74+
6875
//TODO this is a backwards way of searching and will cause collisions
6976
// I'm sure the Apache CLI has a better way of navigating this
7077

7178
for(CLICommand command : COMMANDS)
7279
{
80+
System.out.println("OK: " + command.name);
7381
if(cmd.hasOption(command.name))
7482
{
83+
System.out.println("ON: " + command.name);
7584
command.runCommand(cmd);
7685
return;
7786
}
7887
}
7988

80-
handleCLIDecompilation(cmd);
89+
if(isCLI)
90+
handleCLIDecompilation(cmd);
8191
}
8292
catch (Exception e)
8393
{
@@ -144,6 +154,16 @@ private void handleCLIDecompilation(CommandLine cmd)
144154
//TODO decompiling happens here
145155
}
146156

157+
public CLICommand getCommand(String name)
158+
{
159+
for(CLICommand command : COMMANDS)
160+
if(command.name.equals(name)
161+
|| command.nameFormatted.equals(name))
162+
return command;
163+
164+
return null;
165+
}
166+
147167
public boolean isCLI()
148168
{
149169
return isCLI;

src/main/java/the/bytecode/club/bytecodeviewer/cli/CLICommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ public abstract class CLICommand
1010
{
1111

1212
public final String name;
13+
public final String nameFormatted;
1314
public final String description;
1415
public final boolean hasArgs;
1516
public final boolean isCLI;
1617

1718
protected CLICommand(String name, String description, boolean hasArgs, boolean isCLI)
1819
{
1920
this.name = name;
21+
this.nameFormatted = "-" + name;
2022
this.description = description;
2123
this.hasArgs = hasArgs;
2224
this.isCLI = isCLI;

src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/EnglishCommand.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/HelpCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void runCommand(CommandLine cmd)
2828
"-o <output file> Selects the output file",
2929
"-t <target classname> Must either be the fully qualified classname or \"all\" to decompile all as zip",
3030
"-nowait Doesn't wait for the user to read the CLI messages",
31+
3132
"==BCV GUI Commands==",
3233
"-cleanboot Deletes the BCV directory and continues to boot into the GUI",
3334
"-english Forces English language translations"
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package the.bytecode.club.bytecodeviewer.cli.actions.commands;
2+
3+
import org.apache.commons.cli.CommandLine;
4+
import the.bytecode.club.bytecodeviewer.Configuration;
5+
import the.bytecode.club.bytecodeviewer.cli.CLICommand;
6+
import the.bytecode.club.bytecodeviewer.translation.Language;
7+
8+
/**
9+
* @author Konloch
10+
* @since 10/2/2024
11+
*/
12+
public class LanguageCommand extends CLICommand
13+
{
14+
15+
public LanguageCommand()
16+
{
17+
super("language", "Forces specific language translations and continues to boot into the GUI", true, false);
18+
}
19+
20+
@Override
21+
public void runCommand(CommandLine cmd)
22+
{
23+
Language language = Language.ENGLISH;
24+
25+
String inputLanguage = cmd.getOptionValue("language");
26+
String inputLanguageLowerCase = inputLanguage.toLowerCase();
27+
boolean found = false;
28+
29+
//strict matching
30+
for(Language lang : Language.values())
31+
{
32+
if(lang.name().equalsIgnoreCase(inputLanguage))
33+
{
34+
language = lang;
35+
found = true;
36+
break;
37+
}
38+
39+
if(lang.getReadableName().equalsIgnoreCase(inputLanguage))
40+
{
41+
language = lang;
42+
found = true;
43+
break;
44+
}
45+
46+
for(String languageCode : lang.getLanguageCode())
47+
{
48+
if(languageCode.equalsIgnoreCase(inputLanguage))
49+
{
50+
language = lang;
51+
found = true;
52+
break;
53+
}
54+
}
55+
}
56+
57+
//loose matching by name
58+
if(!found)
59+
{
60+
for (Language lang : Language.values())
61+
{
62+
if (lang.name().toLowerCase().contains(inputLanguageLowerCase))
63+
{
64+
language = lang;
65+
found = true;
66+
break;
67+
}
68+
}
69+
}
70+
71+
if(!found)
72+
{
73+
for (Language lang : Language.values())
74+
{
75+
if (lang.getReadableName().toLowerCase().contains(inputLanguageLowerCase))
76+
{
77+
language = lang;
78+
found = true;
79+
break;
80+
}
81+
}
82+
}
83+
84+
//loose matching by language code
85+
if(!found)
86+
{
87+
for (Language lang : Language.values())
88+
{
89+
for(String languageCode : lang.getLanguageCode())
90+
{
91+
if(languageCode.toLowerCase().contains(inputLanguageLowerCase))
92+
{
93+
language = lang;
94+
found = true;
95+
break;
96+
}
97+
}
98+
}
99+
}
100+
101+
if(found)
102+
{
103+
System.out.println("Changing language to: " + language);
104+
105+
Configuration.language = language;
106+
}
107+
else
108+
{
109+
System.out.println("Could not find supported language: " + language);
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)