org.apache.commons.cli.Option.getOpt()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中org.apache.commons.cli.Option.getOpt()方法的一些代码示例,展示了Option.getOpt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.getOpt()方法的具体详情如下:
包路径:org.apache.commons.cli.Option
类名称:Option
方法名:getOpt

Option.getOpt介绍

[英]Retrieve the name of this Option. It is this String which can be used with CommandLine#hasOption(String opt) and CommandLine#getOptionValue(String opt) to check for existence and argument.
[中]检索此选项的名称。这个字符串可以与命令行#haspoption(String opt)和命令行#getOptionValue(String opt)一起使用,以检查存在性和参数。

代码示例

代码示例来源:origin: apache/flink

public ListOptions(CommandLine line) {
  super(line);
  this.showAll = line.hasOption(ALL_OPTION.getOpt());
  this.showRunning = line.hasOption(RUNNING_OPTION.getOpt());
  this.showScheduled = line.hasOption(SCHEDULED_OPTION.getOpt());
}

代码示例来源:origin: apache/flink

public SavepointOptions(CommandLine line) {
  super(line);
  args = line.getArgs();
  dispose = line.hasOption(SAVEPOINT_DISPOSE_OPTION.getOpt());
  disposeSavepointPath = line.getOptionValue(SAVEPOINT_DISPOSE_OPTION.getOpt());
  jarFile = line.getOptionValue(JAR_OPTION.getOpt());
}

代码示例来源:origin: apache/flink

public CancelOptions(CommandLine line) {
  super(line);
  this.args = line.getArgs();
  this.withSavepoint = line.hasOption(CANCEL_WITH_SAVEPOINT_OPTION.getOpt());
  this.targetDirectory = line.getOptionValue(CANCEL_WITH_SAVEPOINT_OPTION.getOpt());
}

代码示例来源:origin: apache/flink

protected CommandLineOptions(CommandLine line) {
  this.printHelp = line.hasOption(HELP_OPTION.getOpt());
}

代码示例来源:origin: apache/flink

@Override
public boolean isActive(CommandLine commandLine) {
  String jobManagerOption = commandLine.getOptionValue(addressOption.getOpt(), null);
  boolean yarnJobManager = ID.equals(jobManagerOption);
  boolean yarnAppId = commandLine.hasOption(applicationId.getOpt());
  return yarnJobManager || yarnAppId || (isYarnPropertiesFileMode(commandLine) && yarnApplicationIdFromYarnProperties != null);
}

代码示例来源:origin: apache/kylin

public boolean hasOption(Option option) {
  return commandLine.hasOption(option.getOpt());
}

代码示例来源:origin: apache/flink

public static SavepointRestoreSettings createSavepointRestoreSettings(CommandLine commandLine) {
  if (commandLine.hasOption(SAVEPOINT_PATH_OPTION.getOpt())) {
    String savepointPath = commandLine.getOptionValue(SAVEPOINT_PATH_OPTION.getOpt());
    boolean allowNonRestoredState = commandLine.hasOption(SAVEPOINT_ALLOW_NON_RESTORED_OPTION.getOpt());
    return SavepointRestoreSettings.forPath(savepointPath, allowNonRestoredState);
  } else {
    return SavepointRestoreSettings.none();
  }
}

代码示例来源:origin: apache/flink

@Override
@Nullable
public ApplicationId getClusterId(CommandLine commandLine) {
  if (commandLine.hasOption(applicationId.getOpt())) {
    return ConverterUtils.toApplicationId(commandLine.getOptionValue(applicationId.getOpt()));
  } else if (isYarnPropertiesFileMode(commandLine)) {
    return yarnApplicationIdFromYarnProperties;
  } else {
    return null;
  }
}

代码示例来源:origin: apache/incubator-gobblin

/**
 * Parse command line.
 */
public static CommandLine parseCommandLine(Options options, String[] args) throws ParseException {
 CommandLineParser parser = new DefaultParser();
 CommandLine cli = parser.parse(options, args);
 if (cli.hasOption(StressTestUtils.HELP_OPT.getOpt())) {
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp( MRStressTest.class.getSimpleName(), OPTIONS);
  System.exit(0);
 }
 return cli;
}

代码示例来源:origin: apache/flink

/**
   * Override configuration settings by specified command line options.
   *
   * @param commandLine containing the overriding values
   * @return Effective configuration with the overridden configuration settings
   */
  protected Configuration applyCommandLineOptionsToConfiguration(CommandLine commandLine) throws FlinkException {
    final Configuration resultingConfiguration = new Configuration(configuration);

    if (commandLine.hasOption(addressOption.getOpt())) {
      String addressWithPort = commandLine.getOptionValue(addressOption.getOpt());
      InetSocketAddress jobManagerAddress = ClientUtils.parseHostPortAddress(addressWithPort);
      setJobManagerAddressInConfig(resultingConfiguration, jobManagerAddress);
    }

    if (commandLine.hasOption(zookeeperNamespaceOption.getOpt())) {
      String zkNamespace = commandLine.getOptionValue(zookeeperNamespaceOption.getOpt());
      resultingConfiguration.setString(HighAvailabilityOptions.HA_CLUSTER_ID, zkNamespace);
    }

    return resultingConfiguration;
  }
}

代码示例来源:origin: apache/flink

private static List<URL> checkUrls(CommandLine line, Option option) {
  if (line.hasOption(option.getOpt())) {
    final String[] urls = line.getOptionValues(option.getOpt());
    return Arrays.stream(urls)
      .distinct()
      .map((url) -> {
        try {
          return Path.fromLocalFile(new File(url).getAbsoluteFile()).toUri().toURL();
        } catch (Exception e) {
          throw new SqlClientException("Invalid path for option '" + option.getLongOpt() + "': " + url, e);
        }
      })
      .collect(Collectors.toList());
  }
  return null;
}

代码示例来源:origin: apache/flink

protected ProgramOptions(CommandLine line) throws CliArgsException {
  super(line);
  String[] args = line.hasOption(ARGS_OPTION.getOpt()) ?
      line.getOptionValues(ARGS_OPTION.getOpt()) :
      line.getArgs();
  if (line.hasOption(JAR_OPTION.getOpt())) {
    this.jarFilePath = line.getOptionValue(JAR_OPTION.getOpt());
  if (line.hasOption(CLASSPATH_OPTION.getOpt())) {
    for (String path : line.getOptionValues(CLASSPATH_OPTION.getOpt())) {
      try {
        classpaths.add(new URL(path));
  this.entryPointClass = line.hasOption(CLASS_OPTION.getOpt()) ?
      line.getOptionValue(CLASS_OPTION.getOpt()) : null;
  if (line.hasOption(PARALLELISM_OPTION.getOpt())) {
    String parString = line.getOptionValue(PARALLELISM_OPTION.getOpt());
    try {
      parallelism = Integer.parseInt(parString);
  stdoutLogging = !line.hasOption(LOGGING_OPTION.getOpt());
  detachedMode = line.hasOption(DETACHED_OPTION.getOpt()) || line.hasOption(
    YARN_DETACHED_OPTION.getOpt());
  shutdownOnAttachedExit = line.hasOption(SHUTDOWN_IF_ATTACHED_OPTION.getOpt());

代码示例来源:origin: apache/incubator-gobblin

private boolean paramsAreValid(CommandLine cli) {
  if (cli.hasOption(HELP.getOpt())) {
   printUsage();
   return false;
  }
  if (!cli.hasOption(KEYSTORE_LOCATION.getOpt())) {
   System.out.println("Must specify keystore location!");
   printUsage();
   return false;
  }
  return true;
 }
}

代码示例来源:origin: apache/flink

private boolean isYarnPropertiesFileMode(CommandLine commandLine) {
  boolean canApplyYarnProperties = !commandLine.hasOption(addressOption.getOpt());
  if (canApplyYarnProperties) {
    for (Option option : commandLine.getOptions()) {
      if (allOptions.hasOption(option.getOpt())) {
        if (!isDetachedOption(option)) {
          // don't resume from properties file if yarn options have been specified
          canApplyYarnProperties = false;
          break;
        }
      }
    }
  }
  return canApplyYarnProperties;
}

代码示例来源:origin: apache/incubator-gobblin

/**
  * Add configurations provided with {@link #CONFIG_OPT} to {@link Configuration}.
  */
 public static void populateConfigFromCli(Configuration configuration, CommandLine cli) {
  String stressorClass = cli.getOptionValue(STRESSOR_OPT.getOpt(), DEFAULT_STRESSOR_CLASS.getName());
  configuration.set(STRESSOR_CLASS, stressorClass);

  if (cli.hasOption(CONFIG_OPT.getOpt())) {
   for (String arg : cli.getOptionValues(CONFIG_OPT.getOpt())) {
    List<String> tokens = Splitter.on(":").limit(2).splitToList(arg);
    if (tokens.size() < 2) {
     throw new IllegalArgumentException("Configurations must be of the form <key>:<value>");
    }
    configuration.set(tokens.get(0), tokens.get(1));
   }
  }
 }
}

代码示例来源:origin: apache/incubator-gobblin

private boolean paramsAreValid(CommandLine cli) {
  if (cli.hasOption(HELP.getOpt())) {
   printUsage();
   return false;
  }
  if (!cli.hasOption(KEYSTORE_LOCATION.getOpt())) {
   System.out.println("Must specify keystore location!");
   printUsage();
   return false;
  }
  return true;
 }
}

代码示例来源:origin: apache/hive

private void parseCommandLine(String[] args) throws ParseException {
 CommandLine cl = new GnuParser().parse(OPTIONS, args);
 listFSRoot = cl.hasOption(LIST_FS_ROOT.getOpt());
 jdoqlQuery = cl.getOptionValue(EXECUTE_JDOQL.getOpt());
 updateLocationParams = cl.getOptionValues(UPDATE_LOCATION.getOpt());
 dryRun = cl.hasOption(DRY_RUN.getOpt());
 serdePropKey = cl.getOptionValue(SERDE_PROP_KEY.getOpt());
 tablePropKey = cl.getOptionValue(TABLE_PROP_KEY.getOpt());
 help = cl.hasOption(HELP.getOpt());
 int commandCount = (isListFSRoot() ? 1 : 0) + (isExecuteJDOQL() ? 1 : 0) + (isUpdateLocation() ? 1 : 0);
 if (commandCount != 1) {
  throw new IllegalArgumentException("exectly one of -listFSRoot, -executeJDOQL, -updateLocation must be set");
 }
 if (updateLocationParams != null && updateLocationParams.length != 2) {
  throw new IllegalArgumentException("HiveMetaTool:updateLocation takes in 2 arguments but was passed " +
    updateLocationParams.length + " arguments");
 }
 if ((dryRun || serdePropKey != null || tablePropKey != null) && !isUpdateLocation()) {
  throw new IllegalArgumentException("-dryRun, -serdePropKey, -tablePropKey may be used only for the " +
    "-updateLocation command");
 }
}

代码示例来源:origin: apache/flink

if (commandLine.hasOption(zookeeperNamespaceOption.getOpt())) {
  String zkNamespace = commandLine.getOptionValue(zookeeperNamespaceOption.getOpt());
  effectiveConfiguration.setString(HA_CLUSTER_ID, zkNamespace);
  if (commandLine.hasOption(zookeeperNamespace.getOpt())){
    zooKeeperNamespace = commandLine.getOptionValue(zookeeperNamespace.getOpt());
  } else {
    zooKeeperNamespace = effectiveConfiguration.getString(HA_CLUSTER_ID, applicationId.toString());
if (commandLine.hasOption(jmMemory.getOpt())) {
  String jmMemoryVal = commandLine.getOptionValue(jmMemory.getOpt());
  if (!MemorySize.MemoryUnit.hasUnit(jmMemoryVal)) {
    jmMemoryVal += "m";
if (commandLine.hasOption(tmMemory.getOpt())) {
  String tmMemoryVal = commandLine.getOptionValue(tmMemory.getOpt());
  if (!MemorySize.MemoryUnit.hasUnit(tmMemoryVal)) {
    tmMemoryVal += "m";
if (commandLine.hasOption(slots.getOpt())) {
  effectiveConfiguration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, Integer.parseInt(commandLine.getOptionValue(slots.getOpt())));

代码示例来源:origin: facebook/stetho

/**
 * @throws ParseException If any args syntax constraint is violated and the dump was not able to
 *     proceed.
 * @throws DumpException Human readable error executing the dump command.
 */
private int doDump(InputStream input, PrintStream out, PrintStream err, String[] args)
  throws ParseException, DumpException {
 CommandLine parsedArgs = mParser.parse(mGlobalOptions.options,
   args,
   true /* stopAtNonOption */);
 if (parsedArgs.hasOption(mGlobalOptions.optionHelp.getOpt())) {
  dumpUsage(out);
  return 0;
 } else if (parsedArgs.hasOption(mGlobalOptions.optionListPlugins.getOpt())) {
  dumpAvailablePlugins(out);
  return 0;
 } else if (!parsedArgs.getArgList().isEmpty()) {
  dumpPluginOutput(input, out, err, parsedArgs);
  return 0;
 } else {
  // Didn't understand the options, spit out help but use a non-success exit code.
  dumpUsage(err);
  return 1;
 }
}

代码示例来源:origin: zhegexiaohuozi/SeimiCrawler

if (cmdLine.hasOption(HELP_OPT.getOpt())) {
  printHelpAndExit(options, 0);
if (cmdLine.hasOption(HTTPD_PORT.getOpt())) {
  String portValue = cmdLine.getOptionValue(HTTPD_PORT.getOpt());
  if (portValue.matches("\\d+")) {
    port = Integer.parseInt(portValue);
if (cmdLine.hasOption(CRAWLER_NAMES.getOpt())) {
  String crawlerNames = cmdLine.getOptionValue(CRAWLER_NAMES.getOpt());
  crawlers = crawlerNames.split(",");

相关文章