本文整理汇总了Java中io.bootique.cli.Cli类的典型用法代码示例。如果您正苦于以下问题:Java Cli类的具体用法?Java Cli怎么用?Java Cli使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cli类属于io.bootique.cli包,在下文中一共展示了Cli类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import io.bootique.cli.Cli; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
//retrieve the cache defined in the declaration file hazelcast.xml
Cache<String, Integer> declarativeCache = cacheManager.get()
.getCache("myCache1", String.class, Integer.class);
//put an entry...
//CacheEntryCreatedListener fires afterwards
declarativeCache.put("1", 1);
//retrieve the cache configured programmatically and contributed into Bootique
Cache<String, String> programmaticCache = cacheManager.get()
.getCache("myCache2", String.class, String.class);
//put an entry...
//CacheEntryCreatedListener fires afterwards
programmaticCache.put("key1", "value1");
return CommandOutcome.succeeded();
}
示例2: run
import io.bootique.cli.Cli; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
//retrieve the cache defined in ehcache.xml
Cache<String, Integer> cache = cacheManager.get()
.getCache("myCache1", String.class, Integer.class);
//put an entry...
//CacheEntryCreatedListener fires afterwards
cache.put("1", 1);
//retrieve the cache configured programmatically and contributed into Bootique
Cache<Long, Long> myCache2 = cacheManager.get()
.getCache("myCache2", Long.class, Long.class);
//put an entry...
//CacheEntryCreatedListener fires afterwards
myCache2.put(1L, 1L);
return CommandOutcome.succeeded();
}
示例3: run
import io.bootique.cli.Cli; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
String topic = cli.optionString(TOPIC_OPT);
if (topic == null) {
return CommandOutcome.failed(-1, "No --topic specified");
}
ProducerConfig<byte[], String> config = ProducerConfig
.charValueConfig()
.bootstrapServers(cli.optionStrings(BOOTSTRAP_SERVER_OPT))
.build();
Producer<byte[], String> producer = kafkaProvider.get().createProducer(DEFAULT_CLUSTER_NAME, config);
shutdownManager.addShutdownHook(() -> {
producer.close();
// give a bit of time to stop..
Thread.sleep(200);
});
return runConsole(topic, producer);
}
示例4: run
import io.bootique.cli.Cli; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
DataSource dataSource = dataSourceFactoryProvider.get().forName("test1");
try (Connection c = dataSource.getConnection()) {
prepareDB(c);
for (String sql : cli.optionStrings("sql")) {
runSELECT(c, sql);
}
} catch (SQLException ex) {
logger.stderr("Error....", ex);
}
return CommandOutcome.succeeded();
}
示例5: run
import io.bootique.cli.Cli; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
System.out.println("SNOMED-CT interactive browser and search.");
boolean quit = false;
while (!quit) {
if (currentConcept() != null) {
System.out.println("****************************************");
System.out.println("Current: "+currentConcept().getConceptId() + ": " + currentConcept().getFullySpecifiedName());
System.out.println("****************************************");
}
System.out.println("Enter command:");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
try {
String line = bufferedReader.readLine();
quit = performCommand(line.trim());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return CommandOutcome.succeeded();
}
示例6: run
import io.bootique.cli.Cli; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
Scheduler scheduler = schedulerProvider.get();
int jobCount;
List<String> jobNames = cli.optionStrings(JOB_OPTION);
if (jobNames == null || jobNames.isEmpty()) {
LOGGER.info("Starting scheduler");
jobCount = scheduler.start();
} else {
LOGGER.info("Starting scheduler for jobs: " + jobNames);
jobCount = scheduler.start(jobNames);
}
LOGGER.info("Started scheduler with {} trigger(s).", jobCount);
return CommandOutcome.succeededAndForkedToBackground();
}
示例7: run
import io.bootique.cli.Cli; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
List<String> jobNames = cli.optionStrings(JOB_OPTION);
if (jobNames == null || jobNames.isEmpty()) {
return CommandOutcome.failed(1,
String.format("No jobs specified. Use '--%s' option to provide job names", JOB_OPTION));
}
LOGGER.info("Will run job(s): " + jobNames);
Scheduler scheduler = schedulerProvider.get();
CommandOutcome outcome;
if (cli.hasOption(SERIAL_OPTION)) {
outcome = runSerial(jobNames, scheduler);
} else {
outcome = runParallel(jobNames, scheduler);
}
return outcome;
}
示例8: run
import io.bootique.cli.Cli; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
// run "before" commands
Collection<CommandOutcome> beforeResults = runBlocking(extraCommands.getBefore());
for (CommandOutcome outcome : beforeResults) {
if (!outcome.isSuccess()) {
// for now returning the first failure...
// TODO: combine all failures into a single message?
return outcome;
}
}
// run "also" commands... pass the logger to log failures
runNonBlocking(extraCommands.getParallel(), this::logOutcome);
return mainCommand.run(cli);
}
示例9: JsonNodeConfigurationFactoryProvider
import io.bootique.cli.Cli; //导入依赖的package包/类
@Inject
public JsonNodeConfigurationFactoryProvider(
ConfigurationSource configurationSource,
Environment environment,
JacksonService jacksonService,
BootLogger bootLogger,
Set<OptionMetadata> optionMetadata,
Set<OptionRefWithConfig> optionDecorators,
Cli cli) {
this.configurationSource = configurationSource;
this.environment = environment;
this.jacksonService = jacksonService;
this.bootLogger = bootLogger;
this.optionMetadata = optionMetadata;
this.optionDecorators = optionDecorators;
this.cli = cli;
}
示例10: testExec_Failure
import io.bootique.cli.Cli; //导入依赖的package包/类
@Test
public void testExec_Failure() {
CommandOutcome outcome = Bootique.app("-a").module(b ->
BQCoreModule.extend(b).addCommand(new Command() {
@Override
public CommandOutcome run(Cli cli) {
return CommandOutcome.failed(-1, "it failed");
}
@Override
public CommandMetadata getMetadata() {
return CommandMetadata.builder("acommand").build();
}
})
).exec();
assertFalse(outcome.isSuccess());
assertEquals(-1, outcome.getExitCode());
assertEquals("it failed", outcome.getMessage());
}
示例11: testExec_Exception
import io.bootique.cli.Cli; //导入依赖的package包/类
@Test
public void testExec_Exception() {
CommandOutcome outcome = Bootique.app("-a").module(b ->
BQCoreModule.extend(b).addCommand(new Command() {
@Override
public CommandOutcome run(Cli cli) {
throw new RuntimeException("test exception");
}
@Override
public CommandMetadata getMetadata() {
return CommandMetadata.builder("acommand").build();
}
})
).exec();
assertFalse(outcome.isSuccess());
assertEquals(1, outcome.getExitCode());
assertNotNull(outcome.getException());
assertEquals("test exception", outcome.getException().getMessage());
}
示例12: testLoadConfiguration_JsonYaml
import io.bootique.cli.Cli; //导入依赖的package包/类
@Test
public void testLoadConfiguration_JsonYaml() {
BQRuntime runtime = testFactory.app("--config=http://127.0.0.1:12025/test1.json",
"--config=http://127.0.0.1:12025/test1.yml").createRuntime();
JsonNodeConfigurationFactoryProvider provider = new JsonNodeConfigurationFactoryProvider(
runtime.getInstance(ConfigurationSource.class), runtime.getInstance(Environment.class),
runtime.getInstance(JacksonService.class), runtime.getBootLogger(),
runtime.getInstance(Key.get((TypeLiteral<Set<OptionMetadata>>) TypeLiteral.get(Types.setOf(OptionMetadata.class)))),
Collections.emptySet(),
runtime.getInstance(Cli.class));
JsonNode config = provider.loadConfiguration(Collections.emptyMap(), Collections.emptyMap());
assertEquals("{\"x\":1,\"a\":\"b\"}", config.toString());
}
示例13: createCli
import io.bootique.cli.Cli; //导入依赖的package包/类
static Cli createCli(String... configOptions) {
Cli cli = mock(Cli.class);
switch (configOptions.length) {
case 0:
when(cli.optionStrings(CliConfigurationSource.CONFIG_OPTION)).thenReturn(Collections.emptyList());
break;
case 1:
when(cli.optionStrings(CliConfigurationSource.CONFIG_OPTION))
.thenReturn(Collections.singletonList(configOptions[0]));
break;
default:
when(cli.optionStrings(CliConfigurationSource.CONFIG_OPTION)).thenReturn(Arrays.asList(configOptions));
break;
}
return cli;
}
示例14: testMultipleDecoratorsForTheSameCommand
import io.bootique.cli.Cli; //导入依赖的package包/类
@Test
public void testMultipleDecoratorsForTheSameCommand() {
Command c1 = mock(Command.class);
when(c1.run(any())).thenReturn(CommandOutcome.succeeded());
Command c2 = mock(Command.class);
when(c2.run(any())).thenReturn(CommandOutcome.succeeded());
testFactory.app("--a")
.module(b -> BQCoreModule.extend(b)
.addCommand(mainCommand)
.decorateCommand(mainCommand.getClass(), CommandDecorator.beforeRun(c1))
.decorateCommand(mainCommand.getClass(), CommandDecorator.beforeRun(c2)))
.createRuntime()
.run();
verify(c1).run(any(Cli.class));
verify(c2).run(any(Cli.class));
assertTrue(mainCommand.isExecuted());
}
示例15: createRunner
import io.bootique.cli.Cli; //导入依赖的package包/类
public LiquibaseRunner createRunner(DataSourceFactory dataSourceFactory,
Function<Collection<ResourceFactory>,
Collection<ResourceFactory>> changeLogMerger,
Cli cli) {
DataSource ds = getDataSource(dataSourceFactory);
if (changeLog != null) {
if (changeLogs != null) {
throw new IllegalStateException("Using both old style 'changeLog' property and new style 'changeLogs'. " +
"You can use either one or the other");
}
String asClasspath = "classpath:" + changeLog;
LOGGER.warn("Using deprecated 'changeLog' property. " +
"Consider switching to 'changeLogs' collection instead. " +
"The new value will be '" + asClasspath + "'");
return new LegacyLiquibaseRunner(changeLog, ds, cli);
}
Collection<ResourceFactory> allChangeLogs = changeLogMerger.apply(changeLogs);
return new LiquibaseRunner(allChangeLogs, ds, cli);
}