org.apache.commons.cli.Options#addRequiredOption ( )源码实例Demo

下面列出了org.apache.commons.cli.Options#addRequiredOption ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: SmoothNLP   文件: ModelImpl.java
public boolean open(String[] args) {
    CommandLineParser parser = new DefaultParser();
    Options options = new Options();
    options.addRequiredOption("m", "model", true, "set FILE for model file");
    options.addOption("n", "nbest", true, "output n-best results");
    options.addOption("v", "verbose", true, "set INT for verbose level");
    options.addOption("c", "cost-factor", true, "set cost factor");

    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch(ParseException e) {
        System.err.println("invalid arguments");
        return false;
    }
    String model = cmd.getOptionValue("m");
    int nbest = Integer.valueOf(cmd.getOptionValue("n", "0"));
    int vlevel = Integer.valueOf(cmd.getOptionValue("v", "0"));
    double costFactor = Double.valueOf(cmd.getOptionValue("c", "1.0"));
    return open(model, nbest, vlevel, costFactor);
}
 
源代码2 项目: java-sdk   文件: DemoActorService.java
/**
 * The main method of this app.
 * @param args The port the app will listen on.
 * @throws Exception An Exception.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "Port the will listen to.");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  final int port = Integer.parseInt(cmd.getOptionValue("port"));

  // Idle timeout until actor instance is deactivated.
  ActorRuntime.getInstance().getConfig().setActorIdleTimeout(Duration.ofSeconds(30));
  // How often actor instances are scanned for deactivation and balance.
  ActorRuntime.getInstance().getConfig().setActorScanInterval(Duration.ofSeconds(10));
  // How long to wait until for draining an ongoing API call for an actor instance.
  ActorRuntime.getInstance().getConfig().setDrainOngoingCallTimeout(Duration.ofSeconds(10));
  // Determines whether to drain API calls for actors instances being balanced.
  ActorRuntime.getInstance().getConfig().setDrainBalancedActors(true);

  // Register the Actor class.
  ActorRuntime.getInstance().registerActor(DemoActorImpl.class);

  // Start Dapr's callback endpoint.
  DaprApplication.start(port);
}
 
源代码3 项目: rapid   文件: AgentWithNettyMessaging.java
public static void main(final String[] args) throws ParseException {
    final Options options = new Options();
    options.addRequiredOption("l", "listenAddress", true, "The listening addresses Rapid Cluster instances");
    options.addRequiredOption("s", "seedAddress", true, "The seed node's address for the bootstrap protocol");
    final CommandLineParser parser = new DefaultParser();
    final CommandLine cmd = parser.parse(options, args);

    // Get CLI options
    final HostAndPort listenAddress = HostAndPort.fromString(cmd.getOptionValue("listenAddress"));
    final HostAndPort seedAddress = HostAndPort.fromString(cmd.getOptionValue("seedAddress"));

    // Bring up Rapid node
    try {
        final AgentWithNettyMessaging agent = new AgentWithNettyMessaging(listenAddress, seedAddress);
        agent.startCluster();
        for (int i = 0; i < MAX_TRIES; i++) {
            agent.printClusterMembership();
            Thread.sleep(SLEEP_INTERVAL_MS);
        }
    } catch (final IOException | InterruptedException e) {
        LOG.error("Exception thrown by StandaloneAgent {}", e);
        Thread.currentThread().interrupt();
    }
}
 
源代码4 项目: rapid   文件: StandaloneAgent.java
public static void main(final String[] args) throws ParseException {
    final Options options = new Options();
    options.addRequiredOption("l", "listenAddress", true, "The listening addresses Rapid Cluster instances");
    options.addRequiredOption("s", "seedAddress", true, "The seed node's address for the bootstrap protocol");
    final CommandLineParser parser = new DefaultParser();
    final CommandLine cmd = parser.parse(options, args);

    // Get CLI options
    final HostAndPort listenAddress = HostAndPort.fromString(cmd.getOptionValue("listenAddress"));
    final HostAndPort seedAddress = HostAndPort.fromString(cmd.getOptionValue("seedAddress"));

    // Bring up Rapid node
    try {
        final StandaloneAgent agent = new StandaloneAgent(listenAddress, seedAddress);
        agent.startCluster();
        for (int i = 0; i < MAX_TRIES; i++) {
            agent.printClusterMembership();
            Thread.sleep(SLEEP_INTERVAL_MS);
        }
    } catch (final IOException | InterruptedException e) {
        LOG.error("Exception thrown by StandaloneAgent {}", e);
        Thread.currentThread().interrupt();
    }
}
 
源代码5 项目: java-sdk   文件: Subscriber.java
/**
 * This is the entry point for this example app, which subscribes to a topic.
 * @param args The port this app will listen on.
 * @throws Exception An Exception on startup.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "The port this app will listen on");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  int port = Integer.parseInt(cmd.getOptionValue("port"));

  // Start Dapr's callback endpoint.
  DaprApplication.start(port);
}
 
源代码6 项目: java-sdk   文件: InputBindingExample.java
/**
 * The entry point of this app.
 * @param args The port this app will listen on.
 * @throws Exception The Exception.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "The port this app will listen on.");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  int port = Integer.parseInt(cmd.getOptionValue("port"));

  // Start Dapr's callback endpoint.
  DaprApplication.start(port);
}
 
源代码7 项目: java-sdk   文件: DemoService.java
/**
 * Starts the service.
 * @param args Expects the port: -p PORT
 * @throws Exception If cannot start service.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "Port to listen to.");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  int port = Integer.parseInt(cmd.getOptionValue("port"));

  DaprApplication.start(port);
}
 
源代码8 项目: java-sdk   文件: HelloWorldService.java
/**
 * This is the main method of this app.
 * @param args The port to listen on.
 * @throws Exception An Exception.
 */
public static void main(String[] args) throws Exception {
  Options options = new Options();
  options.addRequiredOption("p", "port", true, "Port to listen to.");

  CommandLineParser parser = new DefaultParser();
  CommandLine cmd = parser.parse(options, args);

  // If port string is not valid, it will throw an exception.
  int port = Integer.parseInt(cmd.getOptionValue("port"));

  final GrpcHelloWorldDaprService service = new GrpcHelloWorldDaprService();
  service.start(port);
  service.awaitTermination();
}
 
源代码9 项目: atlas   文件: BulkFetchAndUpdate.java
private static CommandLine getCommandLine(String[] args) throws ParseException {
    Options options = new Options();
    options.addRequiredOption("s", "step", true, "Step to run.");
    options.addOption("u", "user", true, "User name.");
    options.addOption("p", "password", true, "Password name.");
    options.addOption("d", "dir", true, "Directory for reading/writing data.");
    options.addOption(OPTION_FROM, "fromDate", true, "Date, in YYYY-MM-DD format, from where to start reading.");

    return new DefaultParser().parse(options, args);
}