From 66f62534c38e4a5f54c08c72b25e5404e0b81462 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Sat, 27 Apr 2024 18:16:08 +0200 Subject: [PATCH] Improved CLI help page formatting --- .../viaproxy/cli/BetterHelpFormatter.java | 21 ++++++++++++++++++- .../viaproxy/ViaProxyConfig.java | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/raphimc/viaproxy/cli/BetterHelpFormatter.java b/src/main/java/net/raphimc/viaproxy/cli/BetterHelpFormatter.java index 990f087..186758a 100644 --- a/src/main/java/net/raphimc/viaproxy/cli/BetterHelpFormatter.java +++ b/src/main/java/net/raphimc/viaproxy/cli/BetterHelpFormatter.java @@ -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(); + } + } diff --git a/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java b/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java index bf8fb9a..7882d12 100644 --- a/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java +++ b/src/main/java/net/raphimc/viaproxy/protocoltranslator/viaproxy/ViaProxyConfig.java @@ -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); }