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 javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.IOException;
import java.lang.instrument.Instrumentation; import java.lang.instrument.Instrumentation;
public class ViaProxy { 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(); Logger.setup();
final boolean hasUI = args.length == 0 && !GraphicsEnvironment.isHeadless(); final boolean hasUI = args.length == 0 && !GraphicsEnvironment.isHeadless();
ConsoleHandler.hookConsole(); ConsoleHandler.hookConsole();
@ -142,12 +143,7 @@ public class ViaProxy {
return; return;
} }
try {
Options.parse(args); Options.parse(args);
} catch (Throwable t) {
Logger.LOGGER.fatal("[" + t.getClass().getSimpleName() + "] " + t.getMessage());
System.exit(0);
}
if (System.getProperty("skipUpdateCheck") == null) { if (System.getProperty("skipUpdateCheck") == null) {
updateCheckThread.start(); updateCheckThread.start();

View file

@ -17,6 +17,7 @@
*/ */
package net.raphimc.viaproxy.cli.options; package net.raphimc.viaproxy.cli.options;
import joptsimple.OptionException;
import joptsimple.OptionParser; import joptsimple.OptionParser;
import joptsimple.OptionSet; import joptsimple.OptionSet;
import joptsimple.OptionSpec; 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)"); 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)); 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)) { if (options.has(help)) {
parser.formatHelpWith(new BetterHelpFormatter()); parser.formatHelpWith(new BetterHelpFormatter());
parser.printHelpOn(Logger.SYSOUT); parser.printHelpOn(Logger.SYSOUT);
System.exit(0); System.exit(1);
} }
BIND_ADDRESS = options.valueOf(bindAddress); BIND_ADDRESS = options.valueOf(bindAddress);