use of com.beust.jcommander.DefaultUsageFormatter in project pulsar by apache.
the class TokensCliUtils method main.
public static void main(String[] args) throws Exception {
Arguments arguments = new Arguments();
JCommander jcommander = new JCommander(arguments);
IUsageFormatter usageFormatter = new DefaultUsageFormatter(jcommander);
CommandCreateSecretKey commandCreateSecretKey = new CommandCreateSecretKey();
jcommander.addCommand("create-secret-key", commandCreateSecretKey);
CommandCreateKeyPair commandCreateKeyPair = new CommandCreateKeyPair();
jcommander.addCommand("create-key-pair", commandCreateKeyPair);
CommandCreateToken commandCreateToken = new CommandCreateToken();
jcommander.addCommand("create", commandCreateToken);
CommandShowToken commandShowToken = new CommandShowToken();
jcommander.addCommand("show", commandShowToken);
CommandValidateToken commandValidateToken = new CommandValidateToken();
jcommander.addCommand("validate", commandValidateToken);
jcommander.addCommand("gen-doc", new Object());
try {
jcommander.parse(args);
if (arguments.help || jcommander.getParsedCommand() == null) {
jcommander.usage();
System.exit(1);
}
} catch (Exception e) {
System.err.println(e);
String chosenCommand = jcommander.getParsedCommand();
usageFormatter.usage(chosenCommand);
System.exit(1);
}
String cmd = jcommander.getParsedCommand();
if (cmd.equals("create-secret-key")) {
commandCreateSecretKey.run();
} else if (cmd.equals("create-key-pair")) {
commandCreateKeyPair.run();
} else if (cmd.equals("create")) {
commandCreateToken.run();
} else if (cmd.equals("show")) {
commandShowToken.run();
} else if (cmd.equals("validate")) {
commandValidateToken.run();
} else if (cmd.equals("gen-doc")) {
CmdGenerateDocs genDocCmd = new CmdGenerateDocs("pulsar");
genDocCmd.addCommand("tokens", jcommander);
genDocCmd.run(null);
} else {
System.err.println("Invalid command: " + cmd);
System.exit(1);
}
}
use of com.beust.jcommander.DefaultUsageFormatter in project IrpTransmogrifier by bengtmartensson.
the class CommandHelp method usage.
public static void usage(PrintStream printStream, String command, JCommander argumentParser) {
argumentParser.setConsole(new DefaultConsole(printStream));
if (command == null)
argumentParser.usage();
else {
DefaultUsageFormatter formatter = new DefaultUsageFormatter(argumentParser);
formatter.usage(command);
}
}
Aggregations