Improved CLI interface

This commit is contained in:
RaphiMC 2023-05-14 22:41:53 +02:00
parent e4b92ecb69
commit f2aeb9f485
2 changed files with 15 additions and 9 deletions

View file

@ -53,6 +53,7 @@ import net.raphimc.viaproxy.util.logging.Logger;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.lang.instrument.Instrumentation;
public class ViaProxy {
@ -92,7 +93,7 @@ public class ViaProxy {
}
}
public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException {
public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException, IOException {
Logger.setup();
final boolean hasUI = args.length == 0 && !GraphicsEnvironment.isHeadless();
ConsoleHandler.hookConsole();
@ -142,12 +143,7 @@ public class ViaProxy {
return;
}
try {
Options.parse(args);
} catch (Throwable t) {
Logger.LOGGER.fatal("[" + t.getClass().getSimpleName() + "] " + t.getMessage());
System.exit(0);
}
Options.parse(args);
if (System.getProperty("skipUpdateCheck") == null) {
updateCheckThread.start();

View file

@ -17,6 +17,7 @@
*/
package net.raphimc.viaproxy.cli.options;
import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
@ -82,11 +83,20 @@ public class Options {
final OptionSpec<Void> legacyClientPassthrough = parser.acceptsAll(asList("legacy_client_passthrough", "legacy_passthrough"), "Allow <= 1.6.4 clients to connect to the backend server (No protocol translation)");
PluginManager.EVENT_MANAGER.call(new PreOptionsParseEvent(parser));
final OptionSet options = parser.parse(args);
final OptionSet options;
try {
options = parser.parse(args);
} catch (OptionException e) {
Logger.LOGGER.error("Error parsing options: " + e.getMessage());
parser.formatHelpWith(new BetterHelpFormatter());
parser.printHelpOn(Logger.SYSOUT);
System.exit(1);
return;
}
if (options.has(help)) {
parser.formatHelpWith(new BetterHelpFormatter());
parser.printHelpOn(Logger.SYSOUT);
System.exit(0);
System.exit(1);
}
BIND_ADDRESS = options.valueOf(bindAddress);