当前位置: 首页>>代码示例>>Java>>正文


Java JCommander.getParsedCommand方法代码示例

本文整理汇总了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;
  }
}
 
开发者ID:Phenomics,项目名称:ontolib,代码行数:29,代码来源:Main.java

示例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);
    }
  }
 
开发者ID:IBM-Cloud,项目名称:gp-watson-conversation,代码行数:28,代码来源:ConversationUtility.java

示例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();
    }
}
 
开发者ID:Meituan-Dianping,项目名称:walle,代码行数:31,代码来源:Main.java

示例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();
    }
 
开发者ID:rm3l,项目名称:now4j,代码行数:51,代码来源:Now.java

示例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);
}
 
开发者ID:e13mort,项目名称:stf-console-client,代码行数:7,代码来源:StfCommander.java

示例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();
        }
    }
}
 
开发者ID:dockstore,项目名称:write_api_service,代码行数:57,代码来源:Client.java

示例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();
    }
}
 
开发者ID:larsgrefer,项目名称:java-sense-hat,代码行数:47,代码来源:SenseHatTester.java

示例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;
}
 
开发者ID:fabric8-updatebot,项目名称:updatebot,代码行数:49,代码来源:UpdateBot.java


注:本文中的com.beust.jcommander.JCommander.getParsedCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。