本文整理汇总了Java中io.dropwizard.cli.Command类的典型用法代码示例。如果您正苦于以下问题:Java Command类的具体用法?Java Command怎么用?Java Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Command类属于io.dropwizard.cli包,在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: command_binds_work
import io.dropwizard.cli.Command; //导入依赖的package包/类
@Test
public void command_binds_work() {
final Command command = mock(Command.class);
final Class<TestCommand> commandClass = TestCommand.class;
Injector injector = Guice.createInjector(new AbstractPlugin() {
@Override
protected void configure() {
bindCommand(command);
bindCommand(commandClass);
}
});
Set<Command> commandSet = injector.getInstance(Keys.Commands);
Set<Class<? extends Command>> commandClassSet = injector.getInstance(Keys.CommandClasses);
assertThat(commandSet, hasSize(1));
assertThat(commandSet, hasItem(command));
assertThat(commandClassSet, hasSize(1));
assertThat(commandClassSet, hasItem(TestCommand.class));
}
示例2: initialize_adds_commands
import io.dropwizard.cli.Command; //导入依赖的package包/类
@Test
public void initialize_adds_commands() {
final Command command = mock(Command.class);
final Class<TestCommand> commandClass = TestCommand.class;
Application application = buildApplication(
new AbstractPlugin() {
@Override
protected void configure() {
bindCommand(command);
bindCommand(commandClass);
}
}
);
new Platform(application).initialize(bootstrap);
verify(bootstrap).addCommand(eq(command));
verify(bootstrap).addCommand(isA(TestCommand.class));
}
示例3: addCommand
import io.dropwizard.cli.Command; //导入依赖的package包/类
private void addCommand(Subparser subparser, Command command) {
commands.put(command.getName(), command);
subparser.addSubparsers().help("available commands");
final Subparser commandSubparser =
subparser.addSubparsers().addParser(command.getName(), false);
command.configure(commandSubparser);
commandSubparser.addArgument("-h", "--help")
.action(new HelpArgumentAction())
.help("show this help message and exit")
.setDefault(Arguments.SUPPRESS);
commandSubparser.description(command.getDescription())
.setDefault(COMMAND_NAME_ATTR, command.getName())
.defaultHelp(true);
}
示例4: generateSubCommands
import io.dropwizard.cli.Command; //导入依赖的package包/类
private static SortedMap<String, Command> generateSubCommands() {
final SortedMap<String, Command> commands = new TreeMap<>();
final UseraddCommand useraddCommand = new UseraddCommand();
commands.put(useraddCommand.getName(), useraddCommand);
final PasswdCommand passwdCommand = new PasswdCommand();
commands.put(passwdCommand.getName(), passwdCommand);
return commands;
}
示例5: generateSubCommands
import io.dropwizard.cli.Command; //导入依赖的package包/类
private static SortedMap<String, Command> generateSubCommands() {
final SortedMap<String, Command> commands = new TreeMap<>();
final GenerateRequestCommand generateRequestCommand = new GenerateRequestCommand();
commands.put(generateRequestCommand.getName(), generateRequestCommand);
final GenerateSpecsCommand generateSpecsCommand = new GenerateSpecsCommand();
commands.put(generateSpecsCommand.getName(), generateSpecsCommand);
return commands;
}
示例6: initialize
import io.dropwizard.cli.Command; //导入依赖的package包/类
@Override
public void initialize(Bootstrap<?> bootstrap) {
this.application = bootstrap.getApplication();
listServices(Bundle.class).forEach(bootstrap::addBundle);
listServices(ConfiguredBundle.class).forEach(bootstrap::addBundle);
listServices(Command.class).forEach(bootstrap::addCommand);
}
示例7: runDropwizardCommandUsingConfig
import io.dropwizard.cli.Command; //导入依赖的package包/类
/**
* Runs a command for the {@link TestApplication} with the given yaml configuration.
*
* @param yamlConfig a <code>String</code> containing the yaml configuration
* @return the TestApplication if successful
* @throws Exception if the command failed
*/
public static TestApplication runDropwizardCommandUsingConfig(final String yamlConfig,
final Function<TestApplication, Command> commandInstantiator) throws Exception {
final TestApplication application = new TestApplication();
final Bootstrap<TestConfiguration> bootstrap = new Bootstrap<>(application);
bootstrap.setConfigurationSourceProvider(new StringConfigurationSourceProvider());
final Command command = commandInstantiator.apply(application);
command.run(bootstrap, new Namespace(Collections.singletonMap("file", yamlConfig)));
return application;
}
示例8: main
import io.dropwizard.cli.Command; //导入依赖的package包/类
public static void main(String[] args)
{
System.out.println("This is simply a way of making sure things compile");
Command ec = new Command("Stuff", "Things"){
@Override
public void configure(Subparser subparser){}
@Override
public void run(Bootstrap<?> bootstrap, Namespace namespace) throws Exception{}
};
System.out.println("" + ec.getName());
}
示例9: printCommands
import io.dropwizard.cli.Command; //导入依赖的package包/类
private void printCommands(final DiagnosticConfig config, final StringBuilder res) {
final List<Class<Command>> commands = service.getCommands();
if (!config.isPrintCommands() || commands.isEmpty()) {
return;
}
// modules will never be empty
res.append(NEWLINE).append(NEWLINE).append(TAB).append("COMMANDS = ").append(NEWLINE);
final List<String> markers = Lists.newArrayList();
for (Class<Command> command : commands) {
markers.clear();
final CommandItemInfo info = service.getData().getInfo(command);
commonMarkers(markers, info);
if (info.isEnvironmentCommand()) {
markers.add("GUICE_ENABLED");
}
res.append(TAB).append(TAB).append(renderClassLine(command, markers)).append(NEWLINE);
}
}
示例10: registerCommands
import io.dropwizard.cli.Command; //导入依赖的package包/类
/**
* Register commands resolved with classpath scan.
*
* @param commands installed commands
* @see ru.vyarus.dropwizard.guice.GuiceBundle.Builder#searchCommands()
*/
public void registerCommands(final List<Class<Command>> commands) {
setScope(ClasspathScanner.class);
for (Class<Command> cmd : commands) {
register(ConfigItem.Command, cmd);
}
closeScope();
}
示例11: initCommands
import io.dropwizard.cli.Command; //导入依赖的package包/类
/**
* Inject dependencies into all registered environment commands. (only field and setter injection could be used)
* There is no need to process other commands, because only environment commands will run bundles and so will
* start the injector.
*
* @param commands registered commands
* @param injector guice injector object
* @param tracker stats tracker
*/
public static void initCommands(final List<Command> commands, final Injector injector,
final StatsTracker tracker) {
final Stopwatch timer = tracker.timer(CommandTime);
if (commands != null) {
for (Command cmd : commands) {
if (cmd instanceof EnvironmentCommand) {
injector.injectMembers(cmd);
}
}
}
timer.stop();
}
示例12: buildBinders
import io.dropwizard.cli.Command; //导入依赖的package包/类
private void buildBinders() {
if (!bindersBuilt) {
jerseyBinder = Multibinder.newSetBinder(binder(), Object.class, Graceland.class);
managedBinder = Multibinder.newSetBinder(binder(), Managed.class, Graceland.class);
managedClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.ManagedClass, Graceland.class);
healthCheckBinder = Multibinder.newSetBinder(binder(), HealthCheck.class, Graceland.class);
healthCheckClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.HealthCheckClass, Graceland.class);
taskBinder = Multibinder.newSetBinder(binder(), Task.class, Graceland.class);
taskClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.TaskClass, Graceland.class);
bundleBinder = Multibinder.newSetBinder(binder(), Bundle.class, Graceland.class);
bundleClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.BundleClass, Graceland.class);
commandBinder = Multibinder.newSetBinder(binder(), Command.class, Graceland.class);
commandClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.CommandClass, Graceland.class);
initializerBinder = Multibinder.newSetBinder(binder(), Initializer.class, Graceland.class);
initializerClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.InitializerClass, Graceland.class);
configuratorBinder = Multibinder.newSetBinder(binder(), Configurator.class, Graceland.class);
configuratorClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.ConfiguratorClass, Graceland.class);
bindersBuilt = true;
}
}
示例13: initialize
import io.dropwizard.cli.Command; //导入依赖的package包/类
/**
* Ran when the Dropwizard service initializes. This method is responsible for setting up the
* {@link io.dropwizard.Bundle}s and {@link io.dropwizard.cli.Command}s.
*
* @param bootstrap Provided by Dropwizard.
*/
@Override
public void initialize(Bootstrap<PlatformConfiguration> bootstrap) {
for (Initializer initializer : wrapper.getInitializers()) {
initializer.initialize(bootstrap);
LOGGER.debug("Registered Initializer: {}", initializer.getClass().getCanonicalName());
}
for (Bundle bundle : wrapper.getBundles()) {
bootstrap.addBundle(bundle);
LOGGER.debug("Registered Bundle: {}", bundle.getClass().getCanonicalName());
}
for (Command command : wrapper.getCommands()) {
bootstrap.addCommand(command);
LOGGER.debug("Registered Command: {}", command.getClass().getCanonicalName());
}
}
示例14: HierarchicalCommand
import io.dropwizard.cli.Command; //导入依赖的package包/类
protected HierarchicalCommand(String name, String description, SortedMap<String, Command> commands) {
super(name, description);
this.commands = commands;
}
示例15: configure
import io.dropwizard.cli.Command; //导入依赖的package包/类
@Override
public void configure(Subparser subparser) {
for (Map.Entry<String, Command> command : commands.entrySet()) {
addCommand(subparser, command.getValue());
}
}