From 382d177e607fee93fafd8ab3be66f1d0317c2d17 Mon Sep 17 00:00:00 2001 From: Navina Ramesh Date: Wed, 26 Oct 2022 02:24:54 +0530 Subject: [PATCH] Using `usageHelp` instead of deprecated `help` in picocli commands (#9608) --- .../apache/pinot/perf/RawIndexBenchmark.java | 8 ++++++-- .../pinot/tools/AutoAddInvertedIndexTool.java | 2 +- .../apache/pinot/tools/PinotToolLauncher.java | 2 +- .../apache/pinot/tools/SegmentDumpTool.java | 20 +++++++++++-------- .../pinot/tools/UpdateSegmentState.java | 2 +- .../pinot/tools/ValidateTableRetention.java | 2 +- .../RealtimeProvisioningHelperCommand.java | 19 +++++++++++++++--- .../pinot/tools/perf/PerfBenchmarkRunner.java | 13 ++++++------ .../resources/conf/pinot-tools-log4j2.xml | 4 ++-- 9 files changed, 46 insertions(+), 26 deletions(-) diff --git a/pinot-perf/src/main/java/org/apache/pinot/perf/RawIndexBenchmark.java b/pinot-perf/src/main/java/org/apache/pinot/perf/RawIndexBenchmark.java index 06a069070af9..13e9f42e181d 100644 --- a/pinot-perf/src/main/java/org/apache/pinot/perf/RawIndexBenchmark.java +++ b/pinot-perf/src/main/java/org/apache/pinot/perf/RawIndexBenchmark.java @@ -96,7 +96,7 @@ public class RawIndexBenchmark { description = "Number of consecutive docIds to lookup") private int _numConsecutiveLookups = DEFAULT_NUM_CONSECUTIVE_LOOKUP; - @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, help = true, + @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, usageHelp = true, description = "print this message") private boolean _help = false; @@ -302,7 +302,11 @@ public static void main(String[] args) throws Exception { RawIndexBenchmark benchmark = new RawIndexBenchmark(); CommandLine commandLine = new CommandLine(benchmark); - commandLine.parseArgs(args); + CommandLine.ParseResult result = commandLine.parseArgs(args); + if (commandLine.isUsageHelpRequested() || result.matchedArgs().size() == 0) { + commandLine.usage(System.out); + return; + } benchmark.run(); } } diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/AutoAddInvertedIndexTool.java b/pinot-tools/src/main/java/org/apache/pinot/tools/AutoAddInvertedIndexTool.java index e39eb595af7d..5ca98ff6d333 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/AutoAddInvertedIndexTool.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/AutoAddInvertedIndexTool.java @@ -66,7 +66,7 @@ public class AutoAddInvertedIndexTool extends AbstractBaseCommand implements Com + AutoAddInvertedIndex.DEFAULT_MAX_NUM_INVERTED_INDEX_ADDED) private int _maxNumInvertedIndex = AutoAddInvertedIndex.DEFAULT_MAX_NUM_INVERTED_INDEX_ADDED; - @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, help = true, + @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, usageHelp = true, description = "Print this message.") private boolean _help = false; diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/PinotToolLauncher.java b/pinot-tools/src/main/java/org/apache/pinot/tools/PinotToolLauncher.java index 8bea0bd90798..642ff35e1df1 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/PinotToolLauncher.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/PinotToolLauncher.java @@ -43,7 +43,7 @@ public class PinotToolLauncher { SUBCOMMAND_MAP.put("SegmentDump", new SegmentDumpTool()); } - @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, help = true, + @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, usageHelp = true, description = "Print this message.") boolean _help = false; diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/SegmentDumpTool.java b/pinot-tools/src/main/java/org/apache/pinot/tools/SegmentDumpTool.java index 93660bc0a36b..361eb0b61cd4 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/SegmentDumpTool.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/SegmentDumpTool.java @@ -50,12 +50,9 @@ public class SegmentDumpTool extends AbstractBaseCommand implements Command { @CommandLine.Option(names = {"-dumpStarTree"}) private boolean _dumpStarTree = false; - public void doMain(String[] args) - throws Exception { - CommandLine commandLine = new CommandLine(this); - commandLine.parseArgs(args); - dump(); - } + @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, usageHelp = true, + description = "Print this message.") + private boolean _help = false; private void dump() throws Exception { @@ -149,7 +146,14 @@ private void dumpStarTree() public static void main(String[] args) throws Exception { - new SegmentDumpTool().doMain(args); + SegmentDumpTool tool = new SegmentDumpTool(); + CommandLine commandLine = new CommandLine(tool); + CommandLine.ParseResult result = commandLine.parseArgs(args); + if (commandLine.isUsageHelpRequested() || result.matchedArgs().size() == 0) { + commandLine.usage(System.out); + return; + } + tool.execute(); } public String getName() { @@ -170,6 +174,6 @@ public String description() { @Override public boolean getHelp() { - return false; + return _help; } } diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/UpdateSegmentState.java b/pinot-tools/src/main/java/org/apache/pinot/tools/UpdateSegmentState.java index a29efc5c891f..7bd13587ef29 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/UpdateSegmentState.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/UpdateSegmentState.java @@ -60,7 +60,7 @@ public class UpdateSegmentState extends AbstractBaseCommand implements Command { @CommandLine.Option(names = {"-fix"}, required = false, description = "Update IDEALSTATE values (OFFLINE->ONLINE).") private boolean _fix = false; - @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, help = true, + @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, usageHelp = true, description = "Print this message.") private boolean _help = false; diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/ValidateTableRetention.java b/pinot-tools/src/main/java/org/apache/pinot/tools/ValidateTableRetention.java index 4f6cce982b3a..a766642298c4 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/ValidateTableRetention.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/ValidateTableRetention.java @@ -40,7 +40,7 @@ public class ValidateTableRetention extends AbstractBaseCommand implements Comma + " default: " + TableRetentionValidator.DEFAULT_DURATION_IN_DAYS_THRESHOLD) private long _durationInDaysThreshold = TableRetentionValidator.DEFAULT_DURATION_IN_DAYS_THRESHOLD; - @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, help = true, + @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, usageHelp = true, description = "Print this message.") private boolean _help = false; diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/RealtimeProvisioningHelperCommand.java b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/RealtimeProvisioningHelperCommand.java index 975d70f5fdda..a3ca0caca048 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/RealtimeProvisioningHelperCommand.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/admin/command/RealtimeProvisioningHelperCommand.java @@ -100,7 +100,7 @@ public class RealtimeProvisioningHelperCommand extends AbstractBaseAdminCommand description = "Maximum memory per host that can be used for pinot data (e.g. 250G, 100M). Default 48g") private String _maxUsableHostMemory = "48G"; - @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, help = true) + @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, usageHelp = true) private boolean _help = false; public RealtimeProvisioningHelperCommand setTableConfigFile(String tableConfigFile) { @@ -186,7 +186,7 @@ public boolean getHelp() { @Override public void printExamples() { StringBuilder builder = new StringBuilder(); - builder.append("\n\nThis command allows you to estimate the capacity needed for provisioning realtime hosts") + builder.append("\n\nThis command allows you to estimate the capacity needed for provisioning realtime hosts. ") .append("It assumes that there is no upper limit to the amount of memory you can mmap").append( "\nIf you have a hybrid table, then consult the push frequency setting in your offline table specify it in " + "the -pushFrequency argument").append( @@ -197,7 +197,7 @@ public void printExamples() { "\nDoing so will let this program assume that you are willing to take a page hit when querying older data") .append("\nand optimize memory and number of hosts accordingly.") .append("\n See https://docs.pinot.apache.org/operators/operating-pinot/tuning/realtime for details"); - System.out.println(builder.toString()); + System.out.println(builder); } @Override @@ -345,4 +345,17 @@ private T deserialize(File file, Class clazz) { String.format("Cannot read schema file '%s' to '%s' object.", file, clazz.getSimpleName()), e); } } + + public static void main(String[] args) + throws IOException { + RealtimeProvisioningHelperCommand rtProvisioningHelper = new RealtimeProvisioningHelperCommand(); + CommandLine cmdLine = new CommandLine(rtProvisioningHelper); + CommandLine.ParseResult result = cmdLine.parseArgs(args); + if (result.isUsageHelpRequested() || result.matchedArgs().size() == 0) { + cmdLine.usage(System.out); + rtProvisioningHelper.printUsage(); + return; + } + rtProvisioningHelper.execute(); + } } diff --git a/pinot-tools/src/main/java/org/apache/pinot/tools/perf/PerfBenchmarkRunner.java b/pinot-tools/src/main/java/org/apache/pinot/tools/perf/PerfBenchmarkRunner.java index 287c34c3dd38..c816b1eaea37 100644 --- a/pinot-tools/src/main/java/org/apache/pinot/tools/perf/PerfBenchmarkRunner.java +++ b/pinot-tools/src/main/java/org/apache/pinot/tools/perf/PerfBenchmarkRunner.java @@ -80,7 +80,7 @@ public class PerfBenchmarkRunner extends AbstractBaseCommand implements Command description = "Comma separated bloom filter columns to be created (non-batch load).") private String _bloomFilterColumns; - @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, help = true, + @CommandLine.Option(names = {"-help", "-h", "--h", "--help"}, required = false, usageHelp = true, description = "Print this message.") private boolean _help = false; @@ -193,12 +193,11 @@ public static void main(String[] args) throws Exception { PerfBenchmarkRunner perfBenchmarkRunner = new PerfBenchmarkRunner(); CommandLine commandLine = new CommandLine(perfBenchmarkRunner); - commandLine.parseArgs(args); - - if (perfBenchmarkRunner._help) { - perfBenchmarkRunner.printUsage(); - } else { - perfBenchmarkRunner.execute(); + CommandLine.ParseResult result = commandLine.parseArgs(args); + if (result.isUsageHelpRequested() || result.matchedArgs().size() == 0) { + commandLine.usage(System.out); + return; } + commandLine.execute(); } } diff --git a/pinot-tools/src/main/resources/conf/pinot-tools-log4j2.xml b/pinot-tools/src/main/resources/conf/pinot-tools-log4j2.xml index 4ee42efcbd22..c864dd3d0007 100644 --- a/pinot-tools/src/main/resources/conf/pinot-tools-log4j2.xml +++ b/pinot-tools/src/main/resources/conf/pinot-tools-log4j2.xml @@ -21,10 +21,10 @@ --> - + - +