Skip to content

Commit dcb2b95

Browse files
authored
Print usage in autorecovery command if needed (apache#2743)
### Motivation I was trying to read the code to see how auto-recovery service works, just noticed the method `printUsage` was never called and the program doesn't print the usage even when '-h' is specified. ### Changes Print the usage of auto-recovery if '-h' is specified or additional unexpected arguments are provided when running the auto-recovery command.
1 parent ac76a08 commit dcb2b95

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,14 @@ private static ServerConfiguration parseArgs(String[] args)
286286

287287
if (cmdLine.hasOption('c')) {
288288
if (null != leftArgs && leftArgs.length > 0) {
289-
throw new IllegalArgumentException();
289+
throw new IllegalArgumentException("unexpected arguments [" + String.join(" ", leftArgs) + "]");
290290
}
291291
String confFile = cmdLine.getOptionValue("c");
292292
loadConfFile(conf, confFile);
293293
}
294294

295295
if (null != leftArgs && leftArgs.length > 0) {
296-
throw new IllegalArgumentException();
296+
throw new IllegalArgumentException("unexpected arguments [" + String.join(" ", leftArgs) + "]");
297297
}
298298
return conf;
299299
} catch (ParseException e) {
@@ -314,6 +314,11 @@ static int doMain(String[] args) {
314314
try {
315315
conf = parseArgs(args);
316316
} catch (IllegalArgumentException iae) {
317+
LOG.error("Error parsing command line arguments : ", iae);
318+
if (iae.getMessage() != null) {
319+
System.err.println(iae.getMessage());
320+
}
321+
printUsage();
317322
return ExitCode.INVALID_CONF;
318323
}
319324

0 commit comments

Comments
 (0)