use of net.sourceforge.argparse4j.inf.Subparser in project atlasdb by palantir.
the class AtlasDbCliCommand method addOptionToParser.
@VisibleForTesting
static void addOptionToParser(Subparser parser, OptionMetadata option) {
if (option.isHidden()) {
return;
}
List<String> sortedOptions = option.getOptions().stream().sorted((first, second) -> Integer.compareUnsigned(first.length(), second.length())).collect(Collectors.toList());
String longOption = Iterables.getLast(sortedOptions);
Argument arg = parser.addArgument(sortedOptions.toArray(new String[] {})).required(option.isRequired()).help(option.getDescription()).dest(longOption);
if (option.getArity() == 0) {
arg.action(Arguments.storeConst());
arg.setConst(AtlasDbCommandUtils.ZERO_ARITY_ARG_CONSTANT);
} else {
arg.nargs(option.getArity());
}
}
use of net.sourceforge.argparse4j.inf.Subparser in project atlasdb by palantir.
the class AtlasDbCliCommand method addCommandToParser.
private void addCommandToParser(Subparser subparser, CommandMetadata subCommand, List<String> commandRoot) {
Subparser parser = subparser.addSubparsers().addParser(subCommand.getName()).description(subCommand.getDescription()).setDefault(COMMAND_NAME_ATTR, ImmutableList.builder().addAll(commandRoot).add(subCommand.getName()).build());
for (OptionMetadata option : subCommand.getAllOptions()) {
addOptionToParser(parser, option);
}
super.configure(parser);
}
use of net.sourceforge.argparse4j.inf.Subparser in project dropwizard by dropwizard.
the class InheritedServerCommandTest method usesDefaultConfigPath.
@Test
void usesDefaultConfigPath() throws Exception {
class SingletonConfigurationFactory implements ConfigurationFactory<Configuration> {
@Override
public Configuration build(final ConfigurationSourceProvider provider, final String path) {
return configuration;
}
@Override
public Configuration build() {
throw new AssertionError("Didn't use the default config path variable");
}
}
when(configuration.getLoggingFactory()).thenReturn(mock(LoggingFactory.class));
final Bootstrap<Configuration> bootstrap = new Bootstrap<>(application);
bootstrap.setConfigurationFactoryFactory((klass, validator, objectMapper, propertyPrefix) -> new SingletonConfigurationFactory());
bootstrap.addCommand(new ConfiguredCommand<Configuration>("test", "a test command") {
@Override
protected void run(final Bootstrap<Configuration> bootstrap, final Namespace namespace, final Configuration configuration) {
assertThat(namespace.getString("file")).isNotEmpty().isEqualTo("yaml/server.yml");
}
@Override
protected Argument addFileArgument(final Subparser subparser) {
return super.addFileArgument(subparser).setDefault("yaml/server.yml");
}
});
final JarLocation location = mock(JarLocation.class);
when(location.toString()).thenReturn("dw-thing.jar");
when(location.getVersion()).thenReturn(Optional.of("1.0.0"));
Cli cli = new Cli(location, bootstrap, System.out, System.err);
cli.run("test");
}
use of net.sourceforge.argparse4j.inf.Subparser in project dropwizard by dropwizard.
the class Cli method addCommand.
private void addCommand(Command command) {
commands.put(command.getName(), command);
parser.addSubparsers().help("available commands");
final Subparser subparser = parser.addSubparsers().addParser(command.getName(), false);
command.configure(subparser);
addHelp(subparser);
subparser.description(command.getDescription()).setDefault(COMMAND_NAME_ATTR, command.getName()).defaultHelp(true);
}
use of net.sourceforge.argparse4j.inf.Subparser in project dropwizard by dropwizard.
the class DbCommand method configure.
@Override
public void configure(Subparser subparser) {
for (AbstractLiquibaseCommand<T> subcommand : subcommands.values()) {
final Subparser cmdParser = subparser.addSubparsers().addParser(subcommand.getName()).setDefault(COMMAND_NAME_ATTR, subcommand.getName()).description(subcommand.getDescription());
subcommand.configure(cmdParser);
}
}
Aggregations