當前位置: 首頁>>代碼示例>>Java>>正文


Java JCommander.parse方法代碼示例

本文整理匯總了Java中com.beust.jcommander.JCommander.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java JCommander.parse方法的具體用法?Java JCommander.parse怎麽用?Java JCommander.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.beust.jcommander.JCommander的用法示例。


在下文中一共展示了JCommander.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processCommandLineArguments

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
/**
 * Use JCommander to process the provided command-line arguments.
 * This method is an instance method (not static) to allow JCommander
 * to use this instance's JCommander-annotated fields.
 *
 * @param arguments Command-line arguments.
 */
private void processCommandLineArguments(final String[] arguments)
{
   final JCommander commander
      = JCommander.newBuilder()
      .programName("JCommander Demonstration")
      .addObject(this)
      .verbose(1)
      .build();
   commander.parse(arguments);
   if (help)
   {
      commander.usage();
   }
   else
   {
      out.println("The file name provided is '" + file + "' and verbosity is set to " + verbose);
   }
}
 
開發者ID:dustinmarx,項目名稱:java-cli-demos,代碼行數:26,代碼來源:Main.java

示例2: parse

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
/**
 * Parses command line arguments and populates this command line instance.
 * <p>
 * If the command line arguments include the "help" argument, or if the
 * arguments have incorrect values or order, then usage information is
 * printed to {@link System#out} and the program terminates.
 *
 * @param args
 *            the command line arguments
 * @return an instance of the parsed arguments object
 */
public Arguments parse(String[] args) {

    JCommander jCommander = new JCommander(this);
    jCommander.setProgramName("jsonschema2pojo");

    try {
        jCommander.parse(args);

        if (this.showHelp) {
            jCommander.usage();
            exit(EXIT_OKAY);
        }
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        jCommander.usage();
        exit(EXIT_ERROR);
    }

    return this;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:Arguments.java

示例3: main

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
public static void main(String[] args) {
    Injector injector = Guice.createInjector(new MavenModule(), new MavenCommandOptionsModule(), new XmlModule());
    OptionalArgs optionalArgs = injector.getInstance(OptionalArgs.class);
    JCommander jCommander = JCommander.newBuilder().addObject(optionalArgs).build();
    jCommander.setProgramName("mvnUploader");
    jCommander.parse(args);

    if (optionalArgs.isHelp()){
        jCommander.usage();
    } else {
        logger.info("Welcome To Maven Artifacts Uploader");
        Uploader uploader = injector.getInstance(Uploader.class);
        uploader.uploadToRepository(Paths.get(optionalArgs.getPathToArtifacts()));
        logger.info("Done uploading all the artifacts!");
    }
}
 
開發者ID:ronbadur,項目名稱:maven-artifacts-uploader,代碼行數:17,代碼來源:Main.java

示例4: VerbSenseArgumentCounter

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
private VerbSenseArgumentCounter(String... args) {
    JCommander cmd = new JCommander(this);
    cmd.setProgramName(this.getClass().getSimpleName());
    try {
        if (args.length == 0) {
            cmd.usage();
            System.exit(0);
        }
        cmd.parse(args);
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        cmd.usage();
        System.exit(1);
    }
    initializeDb();
    initializeAnnotator();
    validateDir();
}
 
開發者ID:clearwsd,項目名稱:clearwsd,代碼行數:19,代碼來源:VerbSenseArgumentCounter.java

示例5: parse

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
public static Options parse(String[] cliArgs) {
  Options args = new Options();
  JCommander jc = JCommander.newBuilder()
    .addObject(args)
    .build();
  jc.parse(cliArgs);
  if(args.help){
    jc.setProgramName("dremio-admin clean");
    jc.usage();
  }
  return args;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:13,代碼來源:Clean.java

示例6: main

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
@SuppressWarnings("checkstyle:Regexp")
public static void main(final String[] args) throws IOException
{
    final CommandLineArgs commandLineArgs = new CommandLineArgs();
    final JCommander jCommander = new JCommander(commandLineArgs);
    try
    {
        jCommander.parse(args);
    }
    catch (final ParameterException p)
    {
        printUsage(p.getJCommander());
        System.exit(1);
    }

    if (commandLineArgs.isHelp())
    {
        jCommander.usage();
        return;
    }

    final String gitHash = commandLineArgs.getGitHash();
    if (gitHash == null || gitHash.isEmpty())
    {
        System.err.println("-g (GitHash) null or empty");
        printUsage(jCommander);
        System.exit(2);
    }

    final InfluxJmhReportPublisher influxJmhReportPublisher = new InfluxJmhReportPublisher();
    final InfluxJmhReporter influxJmhReporter = new InfluxJmhReporter(influxJmhReportPublisher, new FileReader(),
                                                                      commandLineArgs.getInfluxUrl(),
                                                                      commandLineArgs.getGitHash(),
                                                                      commandLineArgs.getHostname());
    final List<String> jsonFiles = commandLineArgs.getJsonFiles();

    influxJmhReporter.reportResult(jsonFiles);
}
 
開發者ID:TransFICC,項目名稱:influx-jmh-reporter,代碼行數:39,代碼來源:InfluxJmhReporterMain.java

示例7: LuceneIndexReader

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
private LuceneIndexReader(String... args) {
    JCommander cmd = new JCommander(this);
    cmd.setProgramName(this.getClass().getSimpleName());
    try {
        cmd.parse(args);
    } catch (ParameterException e) {
        System.err.println(e.getMessage());
        cmd.usage();
        System.exit(1);
    }
}
 
開發者ID:clearwsd,項目名稱:clearwsd,代碼行數:12,代碼來源:LuceneIndexReader.java

示例8: spaceSeparator

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
@Test
public void spaceSeparator() throws Exception {
  GenerateWorkspaceOptions options = new GenerateWorkspaceOptions();
  JCommander optionParser = JCommander.newBuilder().addObject(options).build();
  optionParser.parse("--artifact", "foo:bar:1.2.3");
  assertThat(options.artifacts).contains("foo:bar:1.2.3");
}
 
開發者ID:bazelbuild,項目名稱:migration-tooling,代碼行數:8,代碼來源:GenerateWorkspaceOptionsTest.java

示例9: noCommaDelimiter

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
@Test
public void noCommaDelimiter() throws Exception {
  GenerateWorkspaceOptions options = new GenerateWorkspaceOptions();
  JCommander optionParser = JCommander.newBuilder().addObject(options).build();
  optionParser.parse("--artifact", "foo:bar:[1.2.3,)");
  assertThat(options.artifacts).contains("foo:bar:[1.2.3,)");
}
 
開發者ID:bazelbuild,項目名稱:migration-tooling,代碼行數:8,代碼來源:GenerateWorkspaceOptionsTest.java

示例10: parse

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
public static BackupManagerOptions parse(String[] cliArgs) {
  BackupManagerOptions args = new BackupManagerOptions();
  JCommander jc = JCommander.newBuilder()
    .addObject(args)
    .build();
  jc.parse(cliArgs);
  if(args.help){
    jc.usage();
    System.exit(0);
  }
  return args;
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:13,代碼來源:Backup.java

示例11: 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

示例12: EmbeddingBinarizer

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
private EmbeddingBinarizer(String... args) {
    JCommander cmd = new JCommander(this);
    cmd.setProgramName(this.getClass().getSimpleName());
    try {
        cmd.parse(args);
    } catch (ParameterException e) {
        System.out.println(e.getMessage());
        cmd.usage();
        System.exit(1);
    }
}
 
開發者ID:clearwsd,項目名稱:clearwsd,代碼行數:12,代碼來源:EmbeddingBinarizer.java

示例13: KMeansCalculator

import com.beust.jcommander.JCommander; //導入方法依賴的package包/類
private KMeansCalculator(String... args) {
    JCommander cmd = new JCommander(this);
    cmd.setProgramName(this.getClass().getSimpleName());
    try {
        cmd.parse(args);
    } catch (ParameterException e) {
        System.out.println(e.getMessage());
        cmd.usage();
        System.exit(1);
    }
}
 
開發者ID:clearwsd,項目名稱:clearwsd,代碼行數:12,代碼來源:KMeansCalculator.java

示例14: 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

示例15: 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


注:本文中的com.beust.jcommander.JCommander.parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。