Search in sources :

Example 6 with IUsageFormatter

use of com.beust.jcommander.IUsageFormatter 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);
    }
}
Also used : ParameterException(com.beust.jcommander.ParameterException) IOException(java.io.IOException) JCommander(com.beust.jcommander.JCommander) CmdGenerateDocs(org.apache.pulsar.common.util.CmdGenerateDocs) IUsageFormatter(com.beust.jcommander.IUsageFormatter) DefaultUsageFormatter(com.beust.jcommander.DefaultUsageFormatter)

Aggregations

IUsageFormatter (com.beust.jcommander.IUsageFormatter)6 DefaultUsageFormatter (com.beust.jcommander.DefaultUsageFormatter)3 JCommander (com.beust.jcommander.JCommander)3 ParameterException (com.beust.jcommander.ParameterException)3 IOException (java.io.IOException)3 CmdGenerateDocs (org.apache.pulsar.common.util.CmdGenerateDocs)3