net.sourceforge.argparse4j.inf.ArgumentParser.handleError()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(13.7k)|赞(0)|评价(0)|浏览(106)

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

ArgumentParser.handleError介绍

[英]Prints usage and error message.

Please note that this method does not terminate the program.
[中]打印用法和错误消息。
请注意,此方法不会终止程序。

代码示例

代码示例来源:origin: spotify/helios

/**
 * Use this instead of calling parser.handle error directly. This will print a header with
 * links to jira and documentation before the standard error message is printed.
 *
 * @param parser the parser which will print the standard error message
 * @param ex     the exception that will be printed
 */
@SuppressWarnings("UseOfSystemOutOrSystemErr")
private void handleError(ArgumentParser parser, ArgumentParserException ex) {
 System.err.println("# " + HELP_ISSUES);
 System.err.println("# " + HELP_WIKI);
 System.err.println("# ---------------------------------------------------------------");
 parser.handleError(ex);
}

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

/**
 * Parses the command line arguments, returning an argparse4j namespace.
 *
 * @param args the arguments to parse
 * @return the namespace
 */
static Namespace parseArgs(String[] args, List<String> unknown) {
 ArgumentParser parser = createParser();
 Namespace namespace = null;
 try {
  namespace = parser.parseKnownArgs(args, unknown);
 } catch (ArgumentParserException e) {
  parser.handleError(e);
  System.exit(1);
 }
 return namespace;
}

代码示例来源:origin: SeldonIO/seldon-server

public static void main(String[] args) throws Exception {
    
    ArgumentParser parser = ArgumentParsers.newArgumentParser("PredictionsToInfluxDb")
        .defaultHelp(true)
        .description("Read Seldon predictions and send stats to influx db");
    parser.addArgument("-t", "--topic").setDefault("Predictions").help("Kafka topic to read from");
    parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port");
    parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port");
    parser.addArgument("-i", "--influxdb").setDefault("localhost:8086").help("Influxdb server and port");
    parser.addArgument("-u", "--influx-user").setDefault("root").help("Influxdb user");
    parser.addArgument("-p", "--influx-password").setDefault("root").help("Influxdb password");
    parser.addArgument("-d", "--influx-database").setDefault("seldon").help("Influxdb database");
    parser.addArgument("--influx-measurement").setDefault("predictions").help("Influxdb Predictions measurement");
    
    Namespace ns = null;
    try {
      ns = parser.parseArgs(args);
      PredictionsToInfluxDb.process(ns);
    } catch (ArgumentParserException e) {
      parser.handleError(e);
      System.exit(1);
    }
  }
}

代码示例来源:origin: SeldonIO/seldon-server

public static void main(String[] args) throws Exception {
  
  ArgumentParser parser = ArgumentParsers.newArgumentParser("ImpressionsToInfluxDb")
      .defaultHelp(true)
      .description("Read Seldon impressions and send stats to influx db");
  parser.addArgument("-t", "--topic").setDefault("impressions").help("Kafka topic to read from");
  parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port");
  parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port");
  parser.addArgument("-i", "--influxdb").setDefault("localhost:8086").help("Influxdb server and port");
  parser.addArgument("-u", "--influx-user").setDefault("root").help("Influxdb user");
  parser.addArgument("-p", "--influx-password").setDefault("root").help("Influxdb password");
  parser.addArgument("-d", "--influx-database").setDefault("seldon").help("Influxdb database");
  parser.addArgument("--influx-measurement-impressions").setDefault("impressions").help("Influxdb impressions measurement");
  parser.addArgument("--influx-measurement-requests").setDefault("requests").help("Influxdb requests measurement");
  
  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
    ImpressionsToInfluxDb.process(ns);
  } catch (ArgumentParserException e) {
    parser.handleError(e);
    System.exit(1);
  }
}

代码示例来源:origin: SeldonIO/seldon-server

public static void main(String[] args) throws Exception {
  
  ArgumentParser parser = ArgumentParsers.newArgumentParser("ImpressionsToInfluxDb")
      .defaultHelp(true)
      .description("Read Seldon impressions and send stats to influx db");
  parser.addArgument("-t", "--topic").setDefault("actions").help("Kafka topic to read from");
  parser.addArgument("-c", "--client").required(true).help("Client to run item similarity");
  parser.addArgument("-o", "--output-topic").required(true).help("Output topic");
  parser.addArgument("-k", "--kafka").setDefault("localhost:9092").help("Kafka server and port");
  parser.addArgument("-z", "--zookeeper").setDefault("localhost:2181").help("Zookeeper server and port");
  parser.addArgument("-w", "--window-secs").type(Integer.class).setDefault(3600*5).help("streaming window size in secs, -1 means ignore");
  parser.addArgument("-u", "--window-processed").type(Integer.class).setDefault(-1).help("streaming window size in processed count, -1 means ignore");
  parser.addArgument("--output-poll-secs").type(Integer.class).setDefault(60).help("output timer polling period in secs");
  parser.addArgument("--hashes").type(Integer.class).setDefault(100).help("number of hashes");
  parser.addArgument("-m", "--min-activity").type(Integer.class).setDefault(200).help("min activity");
  parser.addArgument("-p", "--parse-date-method").choices("json-time","json-utc","system").setDefault("json-time").help("min activity");
  
  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
    ItemSimilarityProcessor processor = new ItemSimilarityProcessor(ns);
    processor.process(ns);
  } catch (ArgumentParserException e) {
    parser.handleError(e);
    System.exit(1);
  }
}

代码示例来源:origin: bazaarvoice/jolt

/**
 * The logic for running DiffyTool has been captured in a helper method that returns a boolean to facilitate unit testing.
 * Since System.exit terminates the JVM it would not be practical to test the main method.
 *
 * @param args the arguments from the command line input
 * @return true if two inputs were read with no differences, false if differences were found or an error was encountered
 */
protected static boolean runJolt( String[] args ) {
  ArgumentParser parser = ArgumentParsers.newArgumentParser( "jolt" );
  Subparsers subparsers = parser.addSubparsers().help( "transform: given a Jolt transform spec, runs the specified transforms on the input data.\n" +
      "diffy: diff two JSON documents.\n" +
      "sort: sort a JSON document alphabetically for human readability." );
  for ( Map.Entry<String, JoltCliProcessor> entry : JOLT_CLI_PROCESSOR_MAP.entrySet() ) {
    entry.getValue().intializeSubCommand( subparsers );
  }
  Namespace ns;
  try {
    ns = parser.parseArgs( args );
  } catch ( ArgumentParserException e ) {
    parser.handleError( e );
    return false;
  }
  JoltCliProcessor joltToolProcessor = JOLT_CLI_PROCESSOR_MAP.get( args[0] );
  if ( joltToolProcessor != null ) {
    return joltToolProcessor.process( ns );
  } else {
    // TODO: error message, print usage. although I don't think it will ever get to this point.
    return false;
  }
}

代码示例来源:origin: spotify/helios

this.options = parser.parseArgs(args);
} catch (ArgumentParserException e) {
 parser.handleError(e);
 throw e;

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

logger.info("If you use LensKit in published research, please see http://lenskit.org/research/");
} catch (ArgumentParserException e) {
  parser.handleError(e);
  System.exit(1);
} catch (LenskitCommandException e) {

代码示例来源:origin: AsamK/signal-cli

ns = parser.parseArgs(args);
} catch (ArgumentParserException e) {
  parser.handleError(e);
  return null;

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

public static void main(String... args) throws Exception {
  ArgumentParser parser = ArgumentParsers.newFor("SynthesizeFile").build()
    .defaultHelp(true)
    .description("Synthesize a text file or ssml file.");
  MutuallyExclusiveGroup group = parser.addMutuallyExclusiveGroup().required(true);
  group.addArgument("--text").help("The text file from which to synthesize speech.");
  group.addArgument("--ssml").help("The ssml file from which to synthesize speech.");

  try {
   Namespace namespace = parser.parseArgs(args);

   if (namespace.get("text") != null) {
    synthesizeTextFile(namespace.getString("text"));
   } else {
    synthesizeSsmlFile(namespace.getString("ssml"));
   }
  } catch (ArgumentParserException e) {
   parser.handleError(e);
  }
 }
}

代码示例来源:origin: com.salesforce.dockerfile-image-update/dockerfile-image-update

public static Namespace handleArguments(ArgumentParser parser, String[] args) {
  Namespace ns = null;
  try {
    ns = parser.parseArgs(args);
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
  return ns;
}

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

public static void main(String... args) throws Exception {

  ArgumentParser parser =
    ArgumentParsers.newFor("SynthesizeText")
      .build()
      .defaultHelp(true)
      .description("Synthesize a text or ssml.");

  MutuallyExclusiveGroup group = parser.addMutuallyExclusiveGroup().required(true);
  group.addArgument("--text").help("The text file from which to synthesize speech.");
  group.addArgument("--ssml").help("The ssml file from which to synthesize speech.");

  try {
   Namespace namespace = parser.parseArgs(args);

   if (namespace.get("text") != null) {
    synthesizeText(namespace.getString("text"));
   } else {
    synthesizeSsml(namespace.getString("ssml"));
   }
  } catch (ArgumentParserException e) {
   parser.handleError(e);
  }
 }
}

代码示例来源:origin: google/graphicsfuzz

public static void main(String[] args) {
 try {
  mainHelper(args);
 } catch (ArgumentParserException exception) {
  exception.getParser().handleError(exception);
  System.exit(1);
 } catch (Throwable ex) {
  ex.printStackTrace();
  System.exit(1);
 }
}

代码示例来源:origin: google/graphicsfuzz

public static void main(String[] args) {
 try {
  mainHelper(args, null);
 } catch (ArgumentParserException exception) {
  exception.getParser().handleError(exception);
  System.exit(1);
 } catch (Exception ex) {
  ex.printStackTrace();
  System.exit(1);
 }
}

代码示例来源:origin: google/graphicsfuzz

public static void main(String[] args) {
 try {
  mainHelper(args);
 } catch (ArgumentParserException exception) {
  exception.getParser().handleError(exception);
  System.exit(1);
 } catch (Throwable ex) {
  ex.printStackTrace();
  System.exit(1);
 }
}

代码示例来源:origin: google/graphicsfuzz

public static void main(String[] args) {
 try {
  mainHelper(args, null);
 } catch (ArgumentParserException exception) {
  exception.getParser().handleError(exception);
  System.exit(1);
 } catch (Throwable ex) {
  ex.printStackTrace();
  System.exit(1);
 }
}

代码示例来源:origin: google/graphicsfuzz

public static void main(String[] args) {
 try {
  mainHelper(args);
 } catch (ArgumentParserException exception) {
  exception.getParser().handleError(exception);
  System.exit(1);
 } catch (IOException | ParseTimeoutException exception) {
  exception.printStackTrace();
  System.exit(1);
 }
}

代码示例来源:origin: google/graphicsfuzz

public static void main(String[] args)
  throws IOException, InterruptedException {
 try {
  mainHelper(args);
 } catch (ArgumentParserException exception) {
  exception.getParser().handleError(exception);
  System.exit(1);
 }
}

代码示例来源:origin: org.opendaylight.controller/netconf-testtool

private static Parameters parseArgs(final String[] args, final ArgumentParser parser) {
  final Parameters opt = new Parameters();
  try {
    parser.parseArgs(args, opt);
    return opt;
  } catch (final ArgumentParserException e) {
    parser.handleError(e);
  }
  System.exit(1);
  return null;
}

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

private static Namespace parseArgs(String[] args) {
  ArgumentParser parser = ArgumentParsers.newFor("Phoenix Canary Test Tool").build()
      .description("Phoenix Canary Test Tool");
  parser.addArgument("--hostname", "-hn").type(String.class).nargs("?").help("Hostname on "
      + "which Phoenix is running.");
  parser.addArgument("--port", "-p").type(String.class).nargs("?").help("Port on " +
      "which Phoenix is running.");
  parser.addArgument("--constring", "-cs").type(String.class).nargs("?").help("Pass an " +
      "explicit connection String to connect to Phoenix. " +
      "default: jdbc:phoenix:thin:serialization=PROTOBUF;url=[hostName:port]");
  parser.addArgument("--timeout", "-t").type(String.class).nargs("?").setDefault("60").help
      ("Maximum time for which the app should run before returning error. default:" + "" +
          " 60 sec");
  parser.addArgument("--testschema", "-ts").type(String.class).nargs("?").setDefault
      (TEST_SCHEMA_NAME).help("Custom name for the test table. " + "default: " +
      TEST_SCHEMA_NAME);
  parser.addArgument("--testtable", "-tt").type(String.class).nargs("?").setDefault
      (TEST_TABLE_NAME).help("Custom name for the test table." + " default: " +
      TEST_TABLE_NAME);
  parser.addArgument("--logsinkclass", "-lsc").type(String.class).nargs("?").setDefault
      ("PhoenixCanaryTool$StdOutSink").help
      ("Path to a Custom implementation for log sink class. default: stdout");
  Namespace res = null;
  try {
    res = parser.parseKnownArgs(args, null);
  } catch (ArgumentParserException e) {
    parser.handleError(e);
  }
  return res;
}

相关文章