Made version parsing more lenient and improved CLI error handling

This commit is contained in:
RaphiMC 2023-06-22 19:50:14 +02:00
parent a0e1732bb9
commit 353b1301e8
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
3 changed files with 43 additions and 38 deletions

View File

@ -84,13 +84,14 @@ public class ViaProxy {
}
try {
transformerManager.hookInstrumentation(Agents.getInstrumentation());
injectedMain("Runtime Agent", args);
} catch (Throwable t) {
final InjectionClassLoader injectionClassLoader = new InjectionClassLoader(transformerManager, ClassLoaders.getSystemClassPath());
injectionClassLoader.setPriority(EnumLoaderPriority.PARENT_FIRST);
Thread.currentThread().setContextClassLoader(injectionClassLoader);
Methods.invoke(null, Methods.getDeclaredMethod(injectionClassLoader.loadClass(ViaProxy.class.getName()), "injectedMain", String.class, String[].class), "Injection ClassLoader", args);
return;
}
injectedMain("Runtime Agent", args);
}
public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException, IOException {

View File

@ -85,13 +85,7 @@ public class Options {
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);
@ -128,6 +122,12 @@ public class Options {
SERVER_HAPROXY_PROTOCOL = options.has(serverHaProxyProtocol);
LEGACY_CLIENT_PASSTHROUGH = options.has(legacyClientPassthrough);
PluginManager.EVENT_MANAGER.call(new PostOptionsParseEvent(options));
} catch (OptionException e) {
Logger.LOGGER.error("Error parsing options: " + e.getMessage());
parser.formatHelpWith(new BetterHelpFormatter());
parser.printHelpOn(Logger.SYSOUT);
System.exit(1);
}
}
}

View File

@ -28,6 +28,10 @@ public class VersionEnumConverter implements ValueConverter<VersionEnum> {
for (VersionEnum version : VersionEnum.getAllVersions()) {
if (version.getName().equalsIgnoreCase(s)) return version;
}
for (VersionEnum version : VersionEnum.getAllVersions()) {
if (version.getProtocol().getIncludedVersions().contains(s)) return version;
}
throw new ValueConversionException("Unable to find version '" + s + "'");
}