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