Improved CLI help page formatting

This commit is contained in:
RaphiMC 2024-04-27 18:16:08 +02:00
parent 6ff8f62aca
commit 66f62534c3
No known key found for this signature in database
GPG key ID: 0F6BB0657A03AC94
2 changed files with 21 additions and 2 deletions

View file

@ -17,15 +17,18 @@
*/
package net.raphimc.viaproxy.cli;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import joptsimple.BuiltinHelpFormatter;
import joptsimple.OptionDescriptor;
import joptsimple.internal.Classes;
import joptsimple.internal.Strings;
import java.util.List;
public class BetterHelpFormatter extends BuiltinHelpFormatter {
public BetterHelpFormatter() {
super(80, 2);
super(120, 2);
}
@Override
@ -40,4 +43,20 @@ public class BetterHelpFormatter extends BuiltinHelpFormatter {
return !Strings.isNullOrEmpty(indicator) && !String.class.getName().equals(indicator) ? Classes.shortNameOf(indicator) : "String";
}
@Override
protected String createDefaultValuesDisplay(List<?> defaultValues) {
if (defaultValues.size() == 1) {
Object value = defaultValues.get(0);
if (value instanceof ProtocolVersion version) {
return version.getName();
} else if (value instanceof String) {
return "\"" + value + "\"";
}
return value.toString();
}
return defaultValues.toString();
}
}

View file

@ -175,7 +175,7 @@ public class ViaProxyConfig extends Config implements com.viaversion.viaversion.
this.optionParser.formatHelpWith(new BetterHelpFormatter());
this.optionParser.printHelpOn(Logger.SYSOUT);
Logger.LOGGER.info("For a more detailed explanation of the options, please refer to the viaproxy.yml file.");
Logger.LOGGER.info("For a more detailed description of the options, please refer to the viaproxy.yml file.");
System.exit(1);
}