Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public void execute(CommandLine cmd) throws Exception {
Preconditions.checkState(cmd.hasOption(DiskBalancerCLI.HELP));
verifyCommandOptions(DiskBalancerCLI.HELP, cmd);
String helpCommand = cmd.getOptionValue(DiskBalancerCLI.HELP);
if (helpCommand == null || helpCommand.isEmpty()) {
// With optionalArg(true), space-separated form "-help <cmd>" leaves the
// sub-command as a positional arg rather than the option's value.
// Fall back to the first leftover arg so "-help plan" works as expected.
String[] leftoverArgs = cmd.getArgs();
if (leftoverArgs != null && leftoverArgs.length > 0) {
helpCommand = leftoverArgs[0];
}
}
if (helpCommand == null || helpCommand.isEmpty()) {
this.printHelp();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,33 @@ public void testHelpCommand() throws Exception {
runCommand(cmdLine);
}

/**
* HDFS-17809: "-help <command>" must display command-specific help text,
* not just the generic usage summary.
*/
@Test
@Timeout(value = 60)
public void testHelpCommandWithSubCommand() throws Exception {
// Each sub-command help should contain its own option/keyword.
String[][] subCommands = {
{PLAN, "plan"},
{EXECUTE, "execute"},
{QUERY, "query"},
{CANCEL, "cancel"},
{REPORT, "report"},
};
for (String[] pair : subCommands) {
String subCmd = pair[0];
String expectedToken = pair[1];
String cmdLine = String.format("hdfs diskbalancer -%s %s", HELP, subCmd);
List<String> output = runCommand(cmdLine);
String joined = String.join("\n", output).toLowerCase();
assertTrue(joined.contains(expectedToken),
"Expected '" + expectedToken + "' in help output for '-help "
+ subCmd + "', got:\n" + joined);
}
}

@Test
public void testPrintFullPathOfPlan()
throws Exception {
Expand Down
Loading