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

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

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

ArgumentParser.parseArgs介绍

[英]Parses command line arguments.

The resulted attributes are returned as Namespace object. This method must not alter the status of this parser and can be called multiple times.
[中]解析命令行参数。
结果属性作为命名空间对象返回。此方法不能改变此解析器的状态,并且可以多次调用。

代码示例

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

parser.printVersion(stdOut);
} else {
  final Namespace namespace = parser.parseArgs(arguments);
  final Command command = requireNonNull(commands.get(namespace.getString(COMMAND_NAME_ATTR)),
    "Command is not found");

代码示例来源:origin: linkedin/kafka-monitor

Namespace res = parser.parseArgs(args);

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

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

代码示例来源: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);

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

Namespace options = parser.parseArgs(args);
Logging.configureLogging(options);
Runtime rt = Runtime.getRuntime();

代码示例来源:origin: io.dropwizard/dropwizard-core

parser.printVersion(stdOut);
} else {
  final Namespace namespace = parser.parseArgs(arguments);
  final Command command = requireNonNull(commands.get(namespace.getString(COMMAND_NAME_ATTR)),
    "Command is not found");

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

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

代码示例来源: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: org.opendaylight.bgpcep/bgp-testtool

static Arguments parseArguments(final String[] args) {
  try {
    final Namespace namespace = ARGUMENT_PARSER.parseArgs(args);
    return new Arguments(namespace);
  } catch (final ArgumentParserException e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源: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: 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: org.opendaylight.controller/netconf-testtool

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

代码示例来源: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: stackoverflow.com

public static void main(String[] args) throws ArgumentParserException {
  ArgumentParser parser = ArgumentParsers.newArgumentParser("prog");
  parser.addArgument("--foo").action(Arguments.storeTrue());
  parser.addArgument("--bar").action(Arguments.storeFalse());
  parser.addArgument("--baz").action(Arguments.storeFalse());
  System.out.println(parser.parseArgs(args));
}

代码示例来源:origin: com.github.born2snipe/cli-pi

public void execute(CliLog log, File workingDirectory, String... args) {
    try {

      CommandContext context = new CommandContext(log, argsParser.parseArgs(args));
      context.setWorkingDirectory(workingDirectory);

      executeParsedArgs(context);
    } catch (HelpScreenException hse) {
      // just eat it
    } catch (ArgumentParserException e) {
      throw new ArgsParsingException(e);
    }
  }
}

相关文章