本文整理汇总了Java中com.beust.jcommander.JCommander.getParsedCommand方法的典型用法代码示例。如果您正苦于以下问题:Java JCommander.getParsedCommand方法的具体用法?Java JCommander.getParsedCommand怎么用?Java JCommander.getParsedCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.beust.jcommander.JCommander
的用法示例。
在下文中一共展示了JCommander.getParsedCommand方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static void main(String[] argv) {
final PrecomputeScoresOptions precomputeScoresOptions = new PrecomputeScoresOptions();
final MergeScoresOptions mergeScoresOptions = new MergeScoresOptions();
final JCommander jc =
JCommander.newBuilder().addCommand(PRECOMPUTE_SCORES, precomputeScoresOptions)
.addCommand(MERGE_SCORES, mergeScoresOptions).build();
try {
jc.parse(argv);
} catch (ParameterException e) {
LOGGER.error("ERROR: " + e.getMessage());
jc.usage();
System.exit(1);
}
if (jc.getParsedCommand() == null) {
jc.usage();
System.exit(1);
}
switch (jc.getParsedCommand()) {
case PRECOMPUTE_SCORES:
new PrecomputeScoresCommand(precomputeScoresOptions).run();
break;
case MERGE_SCORES:
new MergeScoresCommand(mergeScoresOptions).run();
break;
}
}
示例2: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
ConversationUtility conversationCmd = new ConversationUtility();
JCommander jCommander = new JCommander(conversationCmd);
jCommander.setProgramName("Watson Conversation Globalization");
jCommander.addCommand("help", new HelpCmd());
jCommander.addCommand("WCS_To_GP", new WCS_To_GP(), "wcs_to_gp");
jCommander.addCommand("GP_To_WCS", new GP_To_WCS(), "gp_to_wcs");
try {
jCommander.parse(args);
String parsedCommand = jCommander.getParsedCommand();
System.out.println(parsedCommand);
if (parsedCommand == null || parsedCommand.equalsIgnoreCase("help")) {
jCommander.usage();
} else {
BaseUtility parsedCmd = (BaseUtility) jCommander.getCommands().get(parsedCommand).getObjects().get(0);
parsedCmd.execute();
}
} catch (ParameterException e) {
System.err.println(e.getMessage());
jCommander.usage();
System.exit(1);
}
}
示例3: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
final Map<String, IWalleCommand> subCommandList = new HashMap<String, IWalleCommand>();
subCommandList.put("show", new ShowCommand());
subCommandList.put("rm", new RemoveCommand());
subCommandList.put("put", new PutCommand());
subCommandList.put("batch", new BatchCommand());
subCommandList.put("batch2", new Batch2Command());
final WalleCommandLine walleCommandLine = new WalleCommandLine();
final JCommander commander = new JCommander(walleCommandLine);
for (Map.Entry<String, IWalleCommand> commandEntry : subCommandList.entrySet()) {
commander.addCommand(commandEntry.getKey(), commandEntry.getValue());
}
try {
commander.parse(args);
} catch (ParameterException e) {
System.out.println(e.getMessage());
commander.usage();
System.exit(1);
return;
}
walleCommandLine.parse(commander);
final String parseCommand = commander.getParsedCommand();
if (parseCommand != null) {
subCommandList.get(parseCommand).parse();
}
}
示例4: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static void main(String... argv) throws Exception {
//Attempt to determine verbose level first
final Now now = new Now();
JCommander.newBuilder().addObject(now)
.acceptUnknownOptions(true)
.build().parse(argv);
final CommandMain commandMain = new CommandMain();
final JCommander.Builder commanderBuilder = JCommander.newBuilder()
.programName("java -jar now4j-cli-<version>.jar")
.verbose(now.verboseLevel)
.addObject(commandMain);
for (final Map.Entry<String, AbstractCommand> commandEntry : commandMap.entrySet()) {
commanderBuilder.addCommand(commandEntry.getKey(), commandEntry.getValue());
}
final JCommander commander = commanderBuilder.build();
commander.parse(argv);
if (commandMain.help) {
commander.usage();
return;
}
final NowClient nowClient;
final String token = commandMain.token;
if (token == null || token.isEmpty()) {
//Default Now Client, with no option => read from /.now.json file
nowClient = NowClient.create();
} else {
//There is a token option
final String team = commandMain.team;
if (team == null || team.isEmpty()) {
//Read team from /.now.json, if any
nowClient = NowClient.create(token);
} else {
nowClient = NowClient.create(token, team);
}
}
final String parsedCommand = commander.getParsedCommand();
if (!commandMap.containsKey(parsedCommand)) {
throw new IllegalArgumentException("Unsupported command: " +
parsedCommand + ". Possible commands: " + commandMap.keySet());
}
final AbstractCommand abstractCommand = commandMap.get(parsedCommand);
abstractCommand.setNowClient(nowClient);
abstractCommand.work();
}
示例5: create
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
static StfCommander create(StfCommanderContext context, HelpCommandCreator commandCreator, ErrorHandler errorHandler, String... args) {
CommandContainer commandContainer = new CommandContainer(context);
JCommander commander = createCommander(commandContainer, args);
final CommandContainer.Command helpCommand = commandCreator.createHelpCommand(commander);
return new StfCommander(commander.getParsedCommand(), commandContainer, helpCommand, errorHandler);
}
示例6: main
import com.beust.jcommander.JCommander; //导入方法依赖的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();
}
}
}
示例7: main
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
SenseHatTester senseHatTester = new SenseHatTester();
Map<String, Command> commands = new HashMap<>();
commands.put("fill", new FillCommand());
commands.put("set-pixel", new SetPixelCommand());
commands.put("save-image", new SaveImageCommand());
commands.put("load-image", new LoadImageCommand());
commands.put("env", new EnvCommand());
commands.put("pulse", new PulseCommand());
commands.put("text", new TextCommand());
commands.put("clock", new BinaryClockCommand());
JCommander.Builder builder = JCommander.newBuilder()
.addObject(senseHatTester);
commands.forEach((name, cmd) -> builder.addCommand(name, cmd));
JCommander jCommander = builder.build();
jCommander.parse(args);
if(senseHatTester.isPrintUsage()) {
jCommander.usage();
return;
}
String parsedCommand = jCommander.getParsedCommand();
if (parsedCommand != null && commands.containsKey(parsedCommand)) {
SenseHat senseHat;
try {
if(senseHatTester.getFrameBuffer() != null) {
senseHat = new SenseHat(senseHatTester.getFrameBuffer());
} else {
senseHat = new SenseHat();
}
} catch (IllegalStateException e) {
log.error(e.getLocalizedMessage(), e);
return;
}
commands.get(parsedCommand).run(senseHat);
} else {
jCommander.usage();
}
}
示例8: parseCommand
import com.beust.jcommander.JCommander; //导入方法依赖的package包/类
/**
* Parses the command from the given command line arguments or returns null if there is no command found
*/
public static CommandSupport parseCommand(String[] args, Configuration config, boolean defaultToHelp) {
PushSourceChanges pushSourceChanges = new PushSourceChanges();
PushVersionChanges pushVersionChanges = new PushVersionChanges();
PullVersionChanges pullVersionChanges = new PullVersionChanges();
UpdatePullRequests updatePullRequests = new UpdatePullRequests();
Help help = new Help();
JCommander commander = JCommander.newBuilder()
.addObject(config)
.addCommand(HELP, help)
.addCommand(PULL, pullVersionChanges)
.addCommand(PUSH_SOURCE, pushSourceChanges)
.addCommand(PUSH_VERSION, pushVersionChanges)
.addCommand(UPDATE, updatePullRequests)
.build();
commander.setExpandAtSign(false);
commander.setProgramName("updatebot");
commander.parse(args);
help.setCommander(commander);
String parsedCommand = commander.getParsedCommand();
if (parsedCommand != null) {
switch (parsedCommand) {
case HELP:
return help;
case PULL:
return pullVersionChanges;
case PUSH_SOURCE:
return pushSourceChanges;
case PUSH_VERSION:
return pushVersionChanges;
case UPDATE:
return updatePullRequests;
}
}
if (defaultToHelp) {
return help;
}
return null;
}