本文整理汇总了Java中com.beust.jcommander.MissingCommandException类的典型用法代码示例。如果您正苦于以下问题:Java MissingCommandException类的具体用法?Java MissingCommandException怎么用?Java MissingCommandException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MissingCommandException类属于com.beust.jcommander包,在下文中一共展示了MissingCommandException类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.beust.jcommander.MissingCommandException; //导入依赖的package包/类
@SneakyThrows
void run(String[] args) {
if ((args == null || args.length == 0)) {
jc.usage();
return;
}
try {
jc.parse(args);
} catch (MissingCommandException e) {
jc.usage();
return;
}
if (help) {
jc.usage();
return;
}
if (version) {
printVersionInformation();
return;
}
handleCommand();
}
示例2: badCommandTest
import com.beust.jcommander.MissingCommandException; //导入依赖的package包/类
@Test
public void badCommandTest() throws Exception {
JCommander commander = new JCommander();
AddCommandArguments addCommandArguments = new AddCommandArguments();
ImportCommandArguments importCommandArguments = new ImportCommandArguments();
commander.addCommand("add", addCommandArguments);
commander.addCommand("import", importCommandArguments);
String[] args = {"bad", "command"};
Exception exception = null;
try {
commander.parse(args);
} catch (Exception e){
exception = e;
}
Assert.notNull(exception);
Assert.isTrue(exception instanceof MissingCommandException);
}
示例3: parseParams
import com.beust.jcommander.MissingCommandException; //导入依赖的package包/类
private static void parseParams(String[] args) {
try {
params = new CommandLineInterface(args);
} catch (MissingCommandException e) {
logger.error("Invalid command, should be one of these: report, verify");
setExitCode(1);
}
}
示例4: main
import com.beust.jcommander.MissingCommandException; //导入依赖的package包/类
/**
* Used for integration testing
*
* @param argv arguments provided match usage in the dockstore script (i.e. tool launch ...)
*/
public static void main(String[] argv) {
CommandMain commandMain = new CommandMain();
CommandAdd commandAdd = new CommandAdd();
CommandPublish commandPublish = new CommandPublish();
JCommander jc = new JCommander(commandMain);
jc.addCommand("add", commandAdd);
jc.addCommand("publish", commandPublish);
jc.setProgramName("client");
try {
jc.parse(argv);
} catch (MissingCommandException e) {
LOGGER.warn(e.getMessage());
jc.usage();
}
if (commandMain.help) {
jc.usage();
} else {
String command = jc.getParsedCommand();
if (command == null) {
LOGGER.warn("Expecting 'publish' or 'add' command");
jc.usage();
return;
}
switch (command) {
case "add":
if (commandAdd.help) {
jc.usage("add");
} else {
Add add = new Add(commandMain.config);
add.handleAdd(commandAdd.dockerfile, commandAdd.descriptor, commandAdd.secondaryDescriptor, commandAdd.version);
}
break;
case "publish":
if (commandPublish.help) {
jc.usage("publish");
} else {
Publish publish = new Publish(commandMain.config);
publish.handlePublish(commandPublish.tool);
}
break;
default:
// JCommander should've caught this, this should never execute
LOGGER.warn("Unknown command");
jc.usage();
}
}
}
示例5: run
import com.beust.jcommander.MissingCommandException; //导入依赖的package包/类
/**
* Inspects and parses the command line arguments and then passes the results on to the appropriate
* task runner, based upon the {@code command} argument. Prints command line usage if the
* {@code command} is not recognized.
*
* @param args Array of strings representing command line arguments.
* @throws Exception
*/
public void run(String[] args) throws Exception {
Date start = new Date();
logger.debug("[CENTROMERE] Starting CommandLineRunner.");
Assert.notNull(addCommandRunner, "AddCommandRunner must not be null!");
Assert.notNull(importCommandRunner, "ImportCommandRunner must not be null!");
ImportCommandArguments importArguments = new ImportCommandArguments();
AddCommandArguments addArguments = new AddCommandArguments();
JCommander jc = new JCommander();
jc.addCommand("import", importArguments);
jc.addCommand("add", addArguments);
try {
jc.parse(args);
} catch (MissingCommandException e){
logger.debug(String.format("[CENTROMERE] Invalid arguments: add=%s import=%s",
addArguments.toString(), importArguments.toString()));
jc.usage();
}
String command = jc.getParsedCommand() != null ? jc.getParsedCommand() : "null";
logger.debug(String.format("[CENTROMERE] Successfully parsed arguments: add=%s import=%s",
addArguments.toString(), importArguments.toString()));
switch (command) {
case "import":
logger.info(String.format("[CENTROMERE] Running 'import' command with arguments: %s",
importArguments.toString()));
importCommandRunner.run(importArguments);
break;
case "add":
logger.info(String.format("[CENTROMERE] Running 'add' command with arguments: %s",
addArguments.toString()));
addCommandRunner.run(addArguments);
break;
default:
logger.warn(String.format("[CENTROMERE] Invalid command: %s", command));
jc.usage("add");
jc.usage("import");
}
Date end = new Date();
logger.info(String.format("[CENTROMERE] Finished. Elapsed time: %s", formatInterval(end.getTime() - start.getTime())));
}