Skip to content

Commit

Permalink
Fix hangs when type invalid args at command-line (apache#5615)
Browse files Browse the repository at this point in the history
Fixes apache#5533 

*Motivation*

When we using command-line tools, it hangs after type an invalid args.

*Modifications*

We don't need to parse the command, just show the command usage.
  • Loading branch information
zymap authored and sijie committed Nov 19, 2019
1 parent bfcfdf6 commit d16e79a
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ public CmdBase(String cmdName, PulsarAdmin admin) {
jcommander.setProgramName("pulsar-admin " + cmdName);
}

private void tryShowCommandUsage() {
try {
String chosenCommand = jcommander.getParsedCommand();
jcommander.usage(chosenCommand);
} catch (Exception e) {
// it is caused by an invalid command, the invalid command can not be parsed
System.err.println("Invalid command, please use `pulsar-admin --help` to check out how to use");
}
}

public boolean run(String[] args) {
try {
jcommander.parse(args);
} catch (Exception e) {
System.err.println(e.getMessage());
System.err.println();
String chosenCommand = jcommander.getParsedCommand();
jcommander.usage(chosenCommand);
tryShowCommandUsage();
return false;
}

Expand Down

0 comments on commit d16e79a

Please sign in to comment.