Search in sources :

Example 6 with DefaultUsageFormatter

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);
    }
}
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)

Example 7 with DefaultUsageFormatter

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);
    }
}
Also used : DefaultConsole(com.beust.jcommander.internal.DefaultConsole) DefaultUsageFormatter(com.beust.jcommander.DefaultUsageFormatter)

Aggregations

DefaultUsageFormatter (com.beust.jcommander.DefaultUsageFormatter)7 IUsageFormatter (com.beust.jcommander.IUsageFormatter)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 Test (org.testng.annotations.Test)3 DefaultConsole (com.beust.jcommander.internal.DefaultConsole)1