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

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

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

ParseException.getMessage介绍

暂无

代码示例

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

private String parseConfigLocation(String[] args) {
 Options options = new Options();
 options.addOption(CLEANER_CONFIG);
 CommandLine cli;
 try {
  CommandLineParser parser = new DefaultParser();
  cli = parser.parse(options, Arrays.copyOfRange(args, 1, args.length));
 } catch (ParseException pe) {
  System.out.println("Command line parse exception: " + pe.getMessage());
  printUsage(options);
  throw new RuntimeException(pe);
 }
 return cli.getOptionValue(CLEANER_CONFIG.getOpt());
}

代码示例来源:origin: yahoo/mysql_perf_analyzer

private static void readOptionsFromCommandLine(String[] args,
    CommandLineParser parser, Options options, App myServer) {
  try {
    CommandLine commandLine = parser.parse(options, args);
    checkCommandLineContainAvaliableOptions(myServer, commandLine);
  } catch (ParseException exp) {
    System.out.println("Unexpected exception:" + exp.getMessage());
  }
}

代码示例来源:origin: commons-cli/commons-cli

/**
 * Return the <code>Object</code> type of this <code>Option</code>.
 *
 * @param opt the name of the option
 * @return the type of this <code>Option</code>
 * @deprecated due to System.err message. Instead use getParsedOptionValue(String)
 */
@Deprecated
public Object getOptionObject(String opt)
{
  try
  {
    return getParsedOptionValue(opt);
  }
  catch (ParseException pe)
  {
    System.err.println("Exception found converting " + opt + " to desired type: " + pe.getMessage());
    return null;
  }
}

代码示例来源:origin: databricks/learning-spark

public static void setFromCommandLineArgs(Options options, String[] args) {
  CommandLineParser parser = new PosixParser();
  try {
   CommandLine cl = parser.parse(options, args);
   THE_INSTANCE.windowLength = new Duration(Integer.parseInt(
     cl.getOptionValue(LogAnalyzerAppMain.WINDOW_LENGTH, "30")) * 1000);
   THE_INSTANCE.slideInterval = new Duration(Integer.parseInt(
     cl.getOptionValue(LogAnalyzerAppMain.SLIDE_INTERVAL, "5")) * 1000);
   THE_INSTANCE.logsDirectory = cl.getOptionValue(
     LogAnalyzerAppMain.LOGS_DIRECTORY, "/tmp/logs");
   THE_INSTANCE.outputHtmlFile = cl.getOptionValue(
     LogAnalyzerAppMain.OUTPUT_HTML_FILE, "/tmp/log_stats.html");
   THE_INSTANCE.checkpointDirectory = cl.getOptionValue(
     LogAnalyzerAppMain.CHECKPOINT_DIRECTORY, "/tmp/log-analyzer-streaming");
   THE_INSTANCE.indexHtmlTemplate = cl.getOptionValue(
     LogAnalyzerAppMain.INDEX_HTML_TEMPLATE,
     "./src/main/resources/index.html.template");
   THE_INSTANCE.outputDirectory = cl.getOptionValue(
    LogAnalyzerAppMain.OUTPUT_DIRECTORY, "/tmp/pandaout");
   THE_INSTANCE.initialized = true;
  } catch (ParseException e) {
   THE_INSTANCE.initialized = false;
   System.err.println("Parsing failed.  Reason: " + e.getMessage());
  }
 }
}

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

public boolean process(String []argv){
 try {
  commandLine = new GnuParser().parse(options, argv);
  if(commandLine.hasOption("help")){
   printCliUsage();
   return false;
  }
 } catch (ParseException e) {
  System.err.println(e.getMessage());
  printCliUsage();
  return false;
 }
 return true;
}

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

/**
 * Parse the command line arguments
 */
public boolean parse(String[] args) {
 try {
  commandLine = new GnuParser().parse(options, args);
  execString = commandLine.getOptionValue('e');
  fileName = commandLine.getOptionValue('f');
  main = commandLine.getOptionValue("main");
  Properties p = commandLine.getOptionProperties("hiveconf");
  for(String key : p.stringPropertyNames()) {
   vars.put(key, p.getProperty(key));
  }
  p = commandLine.getOptionProperties("hivevar");
  for(String key : p.stringPropertyNames()) {
   vars.put(key, p.getProperty(key));
  }
  p = commandLine.getOptionProperties("define");
  for(String key : p.stringPropertyNames()) {
   vars.put(key, p.getProperty(key));
  }
 } catch (ParseException e) {
  System.err.println(e.getMessage());
  return false;
 }
 return true;
}

代码示例来源:origin: OneBusAway/onebusaway-gtfs-modules

private CommandLine parseCommandLineOptions(String[] args) {
 try {
  Options options = new Options();
  buildOptions(options);
  Parser parser = new PosixParser();
  return parser.parse(options, args);
 } catch (ParseException e) {
  System.err.println(e.getMessage());
  printUsage();
  System.exit(-1);
  return null;
 }
}

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

try {
 Options setPolicyOptions = new Options();
   .withDescription("Path to set policy on")
   .create();
 setPolicyOptions.addOption(pathOption);
   .withDescription("Policy to set")
   .create();
 setPolicyOptions.addOption(policyOption);
 String path = args.getOptionValue(pathOptionName);
 String policy = args.getOptionValue(policyOptionName);
 writeTestOutput("Error parsing options for " + command + " " + pe.getMessage());
} catch (Exception e) {
 writeTestOutput("Caught exception running " + command + ": " + e.getMessage());

代码示例来源:origin: twosigma/beakerx

public OptionsResult parseOptions(String[] args) {
 CommandLineParser parser = new BasicParser();
 List<SparkMagicCommand.SparkOptionCommand> commands = new ArrayList<>();
 try {
  CommandLine cmd = parser.parse(sparkOptions.getOptions(), args);
  if (cmd.hasOption(START)) {
   commands.add((sparkUI, parent) -> sparkMagicCommand.connectToSparkSession(sparkUI, parent));
  }
 } catch (ParseException e) {
  return new ErrorOptionsResult(e.getMessage());
 }
 return new SparkOptionsResult(commands);
}

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

public static CliOptions parseGatewayModeClient(String[] args) {
  try {
    DefaultParser parser = new DefaultParser();
    CommandLine line = parser.parse(GATEWAY_MODE_CLIENT_OPTIONS, args, true);
    return new CliOptions(
      line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
      checkSessionId(line),
      checkUrl(line, CliOptionsParser.OPTION_ENVIRONMENT),
      null,
      checkUrls(line, CliOptionsParser.OPTION_JAR),
      checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
      line.getOptionValue(CliOptionsParser.OPTION_UPDATE.getOpt())
    );
  }
  catch (ParseException e) {
    throw new SqlClientException(e.getMessage());
  }
}

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

String[] args = new String[2];
try {
 Options o = new Options();
 o.addOption(OptUtil.tableOpt());
 args[0] = "-t";
 args[1] = tableName;
} catch (ParseException e) {
 LoggerFactory.getLogger(ShellPluginConfigurationCommand.class)
   .error("Error parsing table: {} {}", Arrays.toString(args), e.getMessage());
 return null;
} catch (TableNotFoundException e) {

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

public static CliOptions parseGatewayModeGateway(String[] args) {
  try {
    DefaultParser parser = new DefaultParser();
    CommandLine line = parser.parse(GATEWAY_MODE_GATEWAY_OPTIONS, args, true);
    return new CliOptions(
      line.hasOption(CliOptionsParser.OPTION_HELP.getOpt()),
      null,
      null,
      checkUrl(line, CliOptionsParser.OPTION_DEFAULTS),
      checkUrls(line, CliOptionsParser.OPTION_JAR),
      checkUrls(line, CliOptionsParser.OPTION_LIBRARY),
      null
    );
  }
  catch (ParseException e) {
    throw new SqlClientException(e.getMessage());
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * Parse the user-specified options, get the generic options, and modify
 * configuration accordingly.
 *
 * @param opts Options to use for parsing args.
 * @param args User-specified arguments
 * @return true if the parse was successful
 */
private boolean parseGeneralOptions(Options opts, String[] args)
  throws IOException {
 opts = buildGeneralOptions(opts);
 CommandLineParser parser = new GnuParser();
 boolean parsed = false;
 try {
  commandLine = parser.parse(opts, preProcessForWindows(args), true);
  processGeneralOptions(commandLine);
  parsed = true;
 } catch(ParseException e) {
  LOG.warn("options parsing failed: "+e.getMessage());
  HelpFormatter formatter = new HelpFormatter();
  formatter.printHelp("general options are: ", opts);
 }
 return parsed;
}

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

private static TxnLogToolkit parseCommandLine(String[] args) throws TxnLogToolkitException, FileNotFoundException {
  CommandLineParser parser = new PosixParser();
  Options options = new Options();
  options.addOption(helpOpt);
  options.addOption(recoverOpt);
  options.addOption(quietOpt);
    CommandLine cli = parser.parse(options, args);
    if (cli.hasOption("help")) {
      printHelpAndExit(0, options);
      printHelpAndExit(1, options);
    if (cli.hasOption("chop") && cli.hasOption("zxid")) {
      return new TxnLogToolkit(cli.getArgs()[0], cli.getOptionValue("zxid"));
    return new TxnLogToolkit(cli.hasOption("recover"), cli.hasOption("verbose"), cli.getArgs()[0], cli.hasOption("yes"));
  } catch (ParseException e) {
    throw new TxnLogToolkitParseException(options, ExitCode.UNEXPECTED_ERROR.getValue(), e.getMessage());

代码示例来源:origin: twosigma/beakerx

public OptionsResult parseOptions(String[] args) {
 CommandLineParser parser = new BasicParser();
 List<EnableSparkSupportCommand> commands = new ArrayList<>();
 try {
  CommandLine cmd = parser.parse(sparkOptions.getOptions(), args);
  if (cmd.hasOption(VERSION)) {
   String version = cmd.getOptionValue(VERSION);
   commands.add((parent) -> actions.loadSpark(parent, version));
  }
 } catch (ParseException e) {
  return new ErrorOptionsResult(e.getMessage());
 }
 return new SparkOptionsResult(commands);
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Sets or gets log level of master and worker through their REST API.
 *
 * @param args same arguments as {@link LogLevel}
 */
public static void main(String[] args) {
 int exitCode = 1;
 try {
  logLevel(args, new InstancedConfiguration(ConfigurationUtils.defaults()));
  exitCode = 0;
 } catch (ParseException e) {
  printHelp("Unable to parse input args: " + e.getMessage());
 } catch (IOException e) {
  e.printStackTrace();
  System.err.println(String.format("Failed to set log level: %s", e.getMessage()));
 }
 System.exit(exitCode);
}

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

/**
 * Parse the arguments.
 * @param args
 */
public void parse(String[] args) {
 try {
  commandLine = new GnuParser().parse(OPTIONS, args);
  if (commandLine.hasOption('h')) {
   printUsage();
   System.exit(1);
  }
  if (commandLine.hasOption('v')) {
   verbose = true;
  }
 } catch (ParseException e) {
  System.err.println(e.getMessage());
  printUsage();
  System.exit(1);
 }
}

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

private static CommandLine parseArguments(Options options, String[] commandLineArguments)
{
  CommandLineParser cmdLineParser = new DefaultParser();
  CommandLine commandLine = null;
  try
  {
    commandLine = cmdLineParser.parse(options, commandLineArguments);
  }
  catch (ParseException parseException)
  {
    System.out.println(parseException.getMessage());
    usage(options);
  }
  return commandLine;
}

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

/**
 * Unsets an erasure coding policy on a directory at the specified path.
 * @param params Parameters passed to the command.
 * @throws Exception if command failed.
 */
private void unsetPolicy(String[] params) throws Exception {
 String command = "unsetPolicy";
 try {
  // unsetPolicy -path <path>
  Options unsetPolicyOptions = new Options();
  String pathOptionName = "path";
  Option pathOption = OptionBuilder.hasArg()
    .isRequired()
    .withLongOpt(pathOptionName)
    .withDescription("Path to unset policy on")
    .create();
  unsetPolicyOptions.addOption(pathOption);
  CommandLine args = parseCommandArgs(unsetPolicyOptions, params);
  String path = args.getOptionValue(pathOptionName);
  erasureCodingShim.unsetErasureCodingPolicy(new Path(path));
  writeTestOutput("Unset EC policy");
 } catch (ParseException pe) {
  writeTestOutput("Error parsing options for " + command + " " + pe.getMessage());
 } catch (Exception e) {
  writeTestOutput("Caught exception running " + command + ": " + e.getMessage());
  throw new Exception("Cannot run " + command + ": " + e.getMessage());
 }
}

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

protected CommandLine doParse(String[] args) throws CommandLineParseException {
  CommandLineParser parser = new DefaultParser();
  CommandLine commandLine;
  try {
    commandLine = parser.parse(options, args);
    if (commandLine.hasOption(HELP_ARG)) {
      return printUsageAndThrow(null, ExitCode.HELP);
    }
    postParse(commandLine);
  } catch (ParseException e) {
    return printUsageAndThrow("Error parsing command line. (" + e.getMessage() + ")", ExitCode.ERROR_PARSING_COMMAND_LINE);
  }
  return commandLine;
}

相关文章