org.kohsuke.args4j.CmdLineException类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(430)

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

CmdLineException介绍

[英]Signals an error in the user input.
[中]发出用户输入错误的信号。

代码示例

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

public void execute(String[] args)
  throws Exception {
 try {
  CmdLineParser parser = new CmdLineParser(this);
  parser.parseArgument(args);
  if ((_subCommand == null) || _help) {
   printUsage();
  } else if (_subCommand.getHelp()) {
   _subCommand.printUsage();
  } else {
   _subCommand.execute();
  }
 } catch (CmdLineException e) {
  LOGGER.error("Error: {}", e.getMessage());
 } catch (Exception e) {
  LOGGER.error("Exception caught: ", e);
 }
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String param = params.getParameter(0);
  Result v = fromString(param.replace('-', '_'));
  if (v==null)
    throw new CmdLineException(owner,"No such status '"+param+"'. Did you mean "+
        EditDistance.findNearest(param.replace('-', '_').toUpperCase(), getNames()));
  setter.addValue(v);
  return 1;
}

代码示例来源:origin: kohsuke/args4j

private int run(String[] args) {
  CmdLineParser p = new CmdLineParser(this);
  try {
    p.parseArgument(args);
    run();
    return 0;
  } catch (CmdLineException e) {
    System.err.println(e.getMessage());
    p.printUsage(System.err);
    return 1;
  }
}

代码示例来源:origin: com.google.testability-explorer/testability-explorer

private void parseArgs(String[] args) throws CmdLineException {
 CmdLineParser parser = new CmdLineParser(this);
 try {
  parser.parseArgument(args);
 } catch (CmdLineException e) {
  System.err.println(e.getMessage() + "\n");
  parser.setUsageWidth(120);
  parser.printUsage(System.err);
  throw new CmdLineException("Exiting...");
 }
}

代码示例来源:origin: org.eclipse.hudson/hudson-remoting

public static void main(String[] args) throws IOException, InterruptedException {
  try {
    _main(args);
  } catch (CmdLineException e) {
    System.err.println(e.getMessage());
    System.err.println("java -jar slave.jar [options...] <secret key> <slave name>");
    new CmdLineParser(new Main()).printUsage(System.err);
  }
}

代码示例来源:origin: jenkinsci/jenkins

parser.parseArgument(args);
stderr.println("ERROR: " + e.getMessage());
printUsage(stderr, parser);
return 2;

代码示例来源:origin: crashinvaders/gdx-texture-packer-gui

public static void main(final String[] args) {
  Arguments arguments = new Arguments();
  try {
    CmdLineParser parser = new CmdLineParser(arguments);
    parser.parseArgument(args);
  } catch (CmdLineException e) {
    System.out.println("Error: " + e.getLocalizedMessage());
    return;
  }
  start(arguments);
}

代码示例来源:origin: net.sf.ofx4j/ofx4j

private void invalidArgs(CmdLineParser parser, CmdLineException e) {
 System.err.println(e.getMessage());
 System.err.println("java DownloadStatement [options...] arguments...");
 // print the list of available options
 parser.printUsage(System.err);
 System.err.println();
 // print option sample. This is useful some time
 System.err.println("  Example: java DownloadStatement " + parser.printExample(ExampleMode.ALL));
 System.exit(1);
}

代码示例来源:origin: org.scala-js/closure-compiler-java-6

/**
 * Parse the given args list.
 */
private void parse(List<String> args) throws CmdLineException {
 parser.parseArgument(args.toArray(new String[] {}));
 compilationLevelParsed =
   COMPILATION_LEVEL_MAP.get(compilationLevel.toUpperCase());
 if (compilationLevelParsed == null) {
  throw new CmdLineException(
    parser, "Bad value for --compilation_level: " + compilationLevel);
 }
}

代码示例来源:origin: jenkinsci/jenkins

@CLIResolver
public RunT getBuildForCLI(@Argument(required=true,metaVar="BUILD#",usage="Build number") String id) throws CmdLineException {
  try {
    int n = Integer.parseInt(id);
    RunT r = getBuildByNumber(n);
    if (r==null)
      throw new CmdLineException(null, "No such build '#"+n+"' exists");
    return r;
  } catch (NumberFormatException e) {
    throw new CmdLineException(null, id+ "is not a number");
  }
}

代码示例来源:origin: args4j/args4j

@Override
public String getLocalizedMessage() {
  if (localizedMessage != null) {
    return localizedMessage;
  } else {
    return getMessage();
  }
}

代码示例来源:origin: Audiveris/audiveris

@Test
public void testRunError ()
    throws Exception
{
  System.out.println("\n+++ testRunError");
  String[] args = new String[]{"-run", "fooBar"};
  try {
    instance.parseParameters(args);
    fail();
  } catch (CmdLineException ex) {
    System.out.println(ex.getMessage());
    System.out.println(ex.getLocalizedMessage());
    assertTrue(ex.getMessage().contains("java.lang.ClassNotFoundException"));
  }
}

代码示例来源:origin: org.bitbucket.ibencher/vagabond

@Override
public int parseArguments(Parameters params) throws CmdLineException {
  if (params.size() != 1)
    throw new CmdLineException ("an option of type log level should have one parameter [trace,debug,info,warn,error,fatal,off]");
  Level result = Level.toLevel(params.getParameter(0).toLowerCase());
  setter.addValue(result);
  log.debug("set log level " + result);
  return 1;
}

代码示例来源:origin: kohsuke/args4j

@Override
public int parseArguments(Parameters params) throws CmdLineException {
  String macString = params.getParameter(0);
  String[] macStringArray = null;
    throw new CmdLineException(owner,
      Messages.ILLEGAL_MAC_ADDRESS, macString);
  setter.asFieldSetter().addValue(mac);		
  return 1;

代码示例来源:origin: kohsuke/args4j

expandedArgs = expandAtFiles(args);
if( isOption(arg) ) {
  currentOptionHandler = isKeyValuePair ? findOptionHandler(arg) : findOptionByName(arg);
    throw new CmdLineException(this, Messages.UNDEFINED_OPTION, arg);
  if (argIndex >= arguments.size()) {
    Messages msg = arguments.size() == 0 ? Messages.NO_ARGUMENT_ALLOWED : Messages.TOO_MANY_ARGUMENTS;
    throw new CmdLineException(this, msg, arg);

代码示例来源:origin: kohsuke/args4j

private void checkRequiredOptionsAndArguments(Set<OptionHandler> present) throws CmdLineException {
  // make sure that all mandatory options are present
  for (OptionHandler handler : options) {
    if(handler.option.required() && !present.contains(handler)) {
      throw new CmdLineException(this, Messages.REQUIRED_OPTION_MISSING, handler.option.toString());
    }
  }
  // make sure that all mandatory arguments are present
  for (OptionHandler handler : arguments) {
    if(handler.option.required() && !present.contains(handler)) {
      throw new CmdLineException(this, Messages.REQUIRED_ARGUMENT_MISSING, handler.option.toString());
    }
  }
  //make sure that all requires arguments are present
  for (OptionHandler handler : present) {
    if (handler.option instanceof NamedOptionDef && !isHandlerHasHisOptions((NamedOptionDef)handler.option, present)) {
      throw new CmdLineException(this, Messages.REQUIRES_OPTION_MISSING,
          handler.option.toString(), Arrays.toString(((NamedOptionDef)handler.option).depends()));
    }
  }
  
  //make sure that all forbids arguments are not present
  for (OptionHandler handler : present) {
    if (handler.option instanceof NamedOptionDef && !isHandlerAllowOtherOptions((NamedOptionDef) handler.option, present)) {
      throw new CmdLineException(this, Messages.FORBIDDEN_OPTION_PRESENT,
          handler.option.toString(), Arrays.toString(((NamedOptionDef) handler.option).forbids()));
    }
  }
}

代码示例来源:origin: kohsuke/args4j

/**
 * Expands every entry prefixed with the AT sign by
 * reading the file. The AT sign is used to reference
 * another file that contains command line options separated
 * by line breaks. 
 * @param args the command line arguments to be preprocessed.
 * @return args with the @ sequences replaced by the text files referenced
 * by the @ sequences, split around the line breaks.
 * @throws CmdLineException 
 */
private String[] expandAtFiles(String args[]) throws CmdLineException {
  List<String> result = new ArrayList<String>();
  for (String arg : args) {
    if (arg.startsWith("@")) {
      File file = new File(arg.substring(1));
      if (!file.exists())
        throw new CmdLineException(this,Messages.NO_SUCH_FILE,file.getPath());
      try {
        result.addAll(readAllLines(file));
      } catch (IOException ex) {
        throw new CmdLineException(this, "Failed to parse "+file,ex);
      }
    } else {
      result.add(arg);
    }
  }
  return result.toArray(new String[result.size()]);
}

代码示例来源:origin: Audiveris/audiveris

private static void processCli (String[] args)
{
  try {
    // First get the provided parameters if any
    cli = new CLI(WellKnowns.TOOL_NAME);
    cli.parseParameters(args);
  } catch (CmdLineException ex) {
    logger.warn("Error in command line: {}", ex.getLocalizedMessage(), ex);
    logger.warn("Exiting ...");
    // Stop the JVM, with failure status (1)
    Runtime.getRuntime().exit(1);
  }
}

代码示例来源:origin: kohsuke/args4j

Class clazz = Class.forName(classname);
  Object bean = clazz.newInstance();
  parser = new CmdLineParser(bean);
  classHasOptions  = hasAnnotation(clazz, Option.class);
  parser.parseArgument(args);
  System.err.println(e.getMessage());
  System.err.print(classname);
  if (classHasOptions)  System.err.print(" [options]");
  System.err.println();
  if (parser != null)
    parser.printUsage(System.err);
} catch (Exception e) {

代码示例来源:origin: org.eclipse.hudson.main/hudson-remoting

public static void main(String[] args) throws IOException, InterruptedException {
  try {
    _main(args);
  } catch (CmdLineException e) {
    System.err.println(e.getMessage());
    System.err.println("java -jar slave.jar [options...] <secret key> <slave name>");
    new CmdLineParser(new Main()).printUsage(System.err);
  }
}

相关文章