ndimiduk commented on code in PR #143:
URL:
https://github.com/apache/hbase-operator-tools/pull/143#discussion_r1634431961
##########
hbase-hbck2/src/test/java/org/apache/hbase/TestHBCKCommandLineParsing.java:
##########
@@ -86,6 +86,19 @@ public void testErrorMessage() throws IOException {
}
}
+ @Test
+ public void testInvalidCommandPrintsError() throws IOException {
+ String output = retrieveOptionOutput(new String[] { "invalidArg", "-h" });
+ assertTrue(output.contains("ERROR:"));
+ }
+
+ @Test
+ public void testPrintsCorrectUsage() throws IOException {
Review Comment:
nit: update the existing `testHelp() instead?
##########
hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java:
##########
@@ -1345,6 +1350,71 @@ private int doCommandLine(CommandLine commandLine,
Options options) throws IOExc
return EXIT_SUCCESS;
}
+ static int showUsagePerCommand(String command, Options options) {
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ writer.println("Command:");
+
+ boolean invalidCommand = false;
+ switch (command) {
+ case ADD_MISSING_REGIONS_IN_META_FOR_TABLES:
+ usageAddFsRegionsMissingInMeta(writer);
+ break;
+ case ASSIGNS:
+ usageAssigns(writer);
+ break;
+ case BYPASS:
+ usageBypass(writer);
+ break;
+ case FILESYSTEM:
+ usageFilesystem(writer);
+ break;
+ case FIX_META:
+ usageFixMeta(writer);
+ break;
+ case GENERATE_TABLE_INFO:
+ usageGenerateMissingTableInfo(writer);
+ break;
+ case REPLICATION:
+ usageReplication(writer);
+ break;
+ case EXTRA_REGIONS_IN_META:
+ usageExtraRegionsInMeta(writer);
+ break;
+ case REPORT_MISSING_REGIONS_IN_META:
+ usageReportMissingRegionsInMeta(writer);
+ break;
+ case SET_REGION_STATE:
+ usageSetRegionState(writer);
+ break;
+ case SET_TABLE_STATE:
+ usageSetTableState(writer);
+ break;
+ case SCHEDULE_RECOVERIES:
+ usageScheduleRecoveries(writer);
+ break;
+ case RECOVER_UNKNOWN:
+ usageRecoverUnknown(writer);
+ break;
+ case UNASSIGNS:
+ usageUnassigns(writer);
+ break;
+ case REGIONINFO_MISMATCH:
+ usageRegioninfoMismatch(writer);
+ break;
+ default:
+ showErrorMessage("Invalid arg: " + command);
+ invalidCommand = true;
+ break;
+ }
+ writer.close();
Review Comment:
Wrap all this in try-with-resources instead of manually closing.
##########
hbase-hbck2/src/main/java/org/apache/hbase/HBCK2.java:
##########
@@ -1507,22 +1577,39 @@ private Pair<CommandLine, List<String>>
parseCommandWithFixAndInputOptions(Strin
return Pair.newPair(commandLine, params);
}
+ private boolean commandHasHelpOption(String[] args) {
Review Comment:
Instead of re-parsing the command line, just pass in the already parsed
`options` that's available from `doCommandLine`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]