Search in sources :

Example 1 with DefaultUsageFormatter

use of com.beust.jcommander.DefaultUsageFormatter in project pulsar by yahoo.

the class DeprecatedCommanderTest method testDeprecatedCommanderWorks.

@Test
public void testDeprecatedCommanderWorks() throws Exception {
    DefaultUsageFormatter defaultUsageFormatter = new DefaultUsageFormatter(cmdTopics.jcommander);
    StringBuilder builder = new StringBuilder();
    defaultUsageFormatter.usage(builder);
    String defaultOutput = builder.toString();
    StringBuilder builder2 = new StringBuilder();
    cmdTopics.jcommander.getUsageFormatter().usage(builder2);
    String outputWithFiltered = builder2.toString();
    assertNotEquals(outputWithFiltered, defaultOutput);
    assertFalse(outputWithFiltered.contains("enable-deduplication"));
    assertTrue(defaultOutput.contains("enable-deduplication"));
    assertFalse(outputWithFiltered.contains("get-max-unacked-messages-on-consumer"));
    assertTrue(defaultOutput.contains("get-max-unacked-messages-on-consumer"));
    assertFalse(outputWithFiltered.contains("get-deduplication"));
    assertTrue(defaultOutput.contains("get-deduplication"));
    // annotation was changed to hidden, reset it.
    cmdTopics = new CmdTopics(() -> admin);
    CmdUsageFormatter formatter = (CmdUsageFormatter) cmdTopics.jcommander.getUsageFormatter();
    formatter.clearDeprecatedCommand();
    StringBuilder builder3 = new StringBuilder();
    cmdTopics.jcommander.getUsageFormatter().usage(builder3);
    String outputAfterClean = builder3.toString();
    assertEquals(outputAfterClean, defaultOutput);
}
Also used : DefaultUsageFormatter(com.beust.jcommander.DefaultUsageFormatter) Test(org.testng.annotations.Test)

Example 2 with DefaultUsageFormatter

use of com.beust.jcommander.DefaultUsageFormatter in project incubator-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 3 with DefaultUsageFormatter

use of com.beust.jcommander.DefaultUsageFormatter in project incubator-pulsar by apache.

the class DeprecatedCommanderTest method testDeprecatedCommanderWorks.

@Test
public void testDeprecatedCommanderWorks() throws Exception {
    DefaultUsageFormatter defaultUsageFormatter = new DefaultUsageFormatter(cmdTopics.jcommander);
    StringBuilder builder = new StringBuilder();
    defaultUsageFormatter.usage(builder);
    String defaultOutput = builder.toString();
    StringBuilder builder2 = new StringBuilder();
    cmdTopics.jcommander.getUsageFormatter().usage(builder2);
    String outputWithFiltered = builder2.toString();
    assertNotEquals(outputWithFiltered, defaultOutput);
    assertFalse(outputWithFiltered.contains("enable-deduplication"));
    assertTrue(defaultOutput.contains("enable-deduplication"));
    assertFalse(outputWithFiltered.contains("get-max-unacked-messages-on-consumer"));
    assertTrue(defaultOutput.contains("get-max-unacked-messages-on-consumer"));
    assertFalse(outputWithFiltered.contains("get-deduplication"));
    assertTrue(defaultOutput.contains("get-deduplication"));
    // annotation was changed to hidden, reset it.
    cmdTopics = new CmdTopics(() -> admin);
    CmdUsageFormatter formatter = (CmdUsageFormatter) cmdTopics.jcommander.getUsageFormatter();
    formatter.clearDeprecatedCommand();
    StringBuilder builder3 = new StringBuilder();
    cmdTopics.jcommander.getUsageFormatter().usage(builder3);
    String outputAfterClean = builder3.toString();
    assertEquals(outputAfterClean, defaultOutput);
}
Also used : DefaultUsageFormatter(com.beust.jcommander.DefaultUsageFormatter) Test(org.testng.annotations.Test)

Example 4 with DefaultUsageFormatter

use of com.beust.jcommander.DefaultUsageFormatter in project pulsar by yahoo.

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 5 with DefaultUsageFormatter

use of com.beust.jcommander.DefaultUsageFormatter in project pulsar by apache.

the class DeprecatedCommanderTest method testDeprecatedCommanderWorks.

@Test
public void testDeprecatedCommanderWorks() throws Exception {
    DefaultUsageFormatter defaultUsageFormatter = new DefaultUsageFormatter(cmdTopics.jcommander);
    StringBuilder builder = new StringBuilder();
    defaultUsageFormatter.usage(builder);
    String defaultOutput = builder.toString();
    StringBuilder builder2 = new StringBuilder();
    cmdTopics.jcommander.getUsageFormatter().usage(builder2);
    String outputWithFiltered = builder2.toString();
    assertNotEquals(outputWithFiltered, defaultOutput);
    assertFalse(outputWithFiltered.contains("enable-deduplication"));
    assertTrue(defaultOutput.contains("enable-deduplication"));
    assertFalse(outputWithFiltered.contains("get-max-unacked-messages-on-consumer"));
    assertTrue(defaultOutput.contains("get-max-unacked-messages-on-consumer"));
    assertFalse(outputWithFiltered.contains("get-deduplication"));
    assertTrue(defaultOutput.contains("get-deduplication"));
    // annotation was changed to hidden, reset it.
    cmdTopics = new CmdTopics(() -> admin);
    CmdUsageFormatter formatter = (CmdUsageFormatter) cmdTopics.jcommander.getUsageFormatter();
    formatter.clearDeprecatedCommand();
    StringBuilder builder3 = new StringBuilder();
    cmdTopics.jcommander.getUsageFormatter().usage(builder3);
    String outputAfterClean = builder3.toString();
    assertEquals(outputAfterClean, defaultOutput);
}
Also used : DefaultUsageFormatter(com.beust.jcommander.DefaultUsageFormatter) Test(org.testng.annotations.Test)

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