balodesecurity commented on code in PR #8324:
URL: https://github.com/apache/hadoop/pull/8324#discussion_r3068004335
##########
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/HelpCommand.java:
##########
@@ -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];
+ }
+ }
Review Comment:
Thanks @ayushtkn, u are right. since normalizeHelpArg() in
DiskBalancerCLI.run() already rewrites -help plan to --help=plan before commons
CLI parses the args, getOptionValue() always returns the sub-command correctly
by the time HelpCommand.execute() is called. The fallback block checking
cmd.getArgs() is dead code, so removing it.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]