当前位置: 首页>>代码示例>>Java>>正文


Java ArgumentParsers.newArgumentParser方法代码示例

本文整理汇总了Java中net.sourceforge.argparse4j.ArgumentParsers.newArgumentParser方法的典型用法代码示例。如果您正苦于以下问题:Java ArgumentParsers.newArgumentParser方法的具体用法?Java ArgumentParsers.newArgumentParser怎么用?Java ArgumentParsers.newArgumentParser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.sourceforge.argparse4j.ArgumentParsers的用法示例。


在下文中一共展示了ArgumentParsers.newArgumentParser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doMain

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
protected void doMain(String args[]) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser(getClass().getSimpleName());

    parser.addArgument("--out")
            .dest("out")
            .metavar("FILE")
            .nargs("?")
            .setDefault("stdout")
            .help("Writes the script to the output file; default is stdout");

    addArguments(parser);

    Namespace namespace = parser.parseArgsOrFail(args);
    String file = namespace.getString("out");

    try (PrintStream out = file.equals("stdout") ? System.out : new PrintStream(new FileOutputStream(file))) {
        generateScript(namespace, out);
    } catch (IOException e) {
        System.err.println("Script generation failed");
        e.printStackTrace(System.err);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:23,代码来源:HiveScriptGenerator.java

示例2: main

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
public static void main(String[] args) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("AngusMe");
    parser.description("Angus SDK configurator");

    parser.addArgument("-s", "--show").action(Arguments.storeTrue())
            .help("display current configuration if exists");

    parser.addArgument("-d", "--delete").action(Arguments.storeTrue())
            .help("remove current configuration if exists");

    try {
        Namespace res = parser.parseArgs(args);
        if (res.getBoolean("show")) {
            show();
        } else if (res.getBoolean("delete")) {
            delete();
        } else {
            update();
        }
    } catch (ArgumentParserException e) {
        parser.handleError(e);
    }
}
 
开发者ID:angus-ai,项目名称:angus-sdk-java,代码行数:24,代码来源:AngusMe.java

示例3: main

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
public static void main(String... args) {
  WSFRealtimeMain m = new WSFRealtimeMain();

  ArgumentParser parser = ArgumentParsers.newArgumentParser("wsf-gtfsrealtime");
  parser.description("Produces a GTFS-realtime feed from the Washington State Ferries API");
  parser.addArgument("--" + ARG_CONFIG_FILE).type(File.class).help("configuration file path");
  Namespace parsedArgs;

  try {
    parsedArgs = parser.parseArgs(args);
    File configFile = parsedArgs.get(ARG_CONFIG_FILE);
    m.run(configFile);
  } catch (CreationException | ConfigurationException | ProvisionException e) {
    _log.error("Error in startup:", e);
    System.exit(-1);
  } catch (ArgumentParserException ex) {
    parser.handleError(ex);
  }
}
 
开发者ID:kurtraschke,项目名称:wsf-gtfsrealtime,代码行数:20,代码来源:WSFRealtimeMain.java

示例4: main

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
/**
 * Main function demonstrating command-line processing via argparse4j.
 *
 * @param arguments Command-line arguments.
 */
public static void main(final String[] arguments)
{
   final ArgumentParser argumentParser =
      ArgumentParsers.newArgumentParser("Main", true);
   argumentParser.addArgument("-f", "--file")
                 .dest("file")
                 .required(true)
                 .help("Path and name of file");
   argumentParser.addArgument("-v", "--verbose")
                 .dest("verbose")
                 .type(Boolean.class)
                 .nargs("?")
                 .setConst(true)
                 .help("Enable verbose output.");

   try
   {
      final Namespace response = argumentParser.parseArgs(arguments);
      final String filePathAndName = response.getString("file");
      final Boolean verbositySet = response.getBoolean("verbose");
      out.println(
           "Path/name of file is '" + filePathAndName
         + "' and verbosity is "
         + (Boolean.TRUE.equals(verbositySet) ? "SET" : "NOT SET")
         + ".");
   }
   catch (ArgumentParserException parserEx)
   {
      argumentParser.handleError(parserEx);
   }
}
 
开发者ID:dustinmarx,项目名称:java-cli-demos,代码行数:37,代码来源:Main.java

示例5: main

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {

        ArgumentParser parser = ArgumentParsers.newArgumentParser("emoparser");
        parser.addArgument("server").required(true).help("server");
        parser.addArgument("emo-config").required(true).help("config.yaml");
        parser.addArgument("config-ddl").required(true).help("config-ddl.yaml");

        // Get the path to config-ddl
        Namespace result = parser.parseArgs(args);

        // Remove config-ddl arg
        new EmoService(result.getString("config-ddl"), new File(result.getString("emo-config")))
                .run((String[]) ArrayUtils.remove(args, 2));
    }
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:15,代码来源:EmoService.java

示例6: main

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
public static void main(String[] args) throws ArgumentParserException
{
    // Constructing parser and subcommands
    ArgumentParser parser = ArgumentParsers.newArgumentParser("bunkr");

    String entrypoint = GuiEntryPoint.class.getName();
    try
    {
        entrypoint = new File(GuiEntryPoint.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getName();
    }
    catch (URISyntaxException ignored) { }

    parser.version(
            String.format("%s\nversion: %s\ncommit date: %s\ncommit hash: %s",
                          entrypoint,
                          Version.versionString,
                          Version.gitDate,
                          Version.gitHash));
    parser.addArgument("--version").action(Arguments.version());
    parser.addArgument("--logging")
            .action(Arguments.storeTrue())
            .type(Boolean.class)
            .setDefault(false)
            .help("Enable debug logging. This may be a security issue due to information leakage.");
    parser.addArgument("--file")
            .type(String.class)
            .help("Open a particular archive by file path");

    Namespace namespace = parser.parseArgs(args);
    if (namespace.getBoolean("logging"))
    {
        Logging.setEnabled(true);
        Logging.info("Logging is now enabled");
    }

    String[] guiParams = new String[]{namespace.get("file")};
    MainApplication.launch(MainApplication.class, guiParams);
}
 
开发者ID:AstromechZA,项目名称:bunkr,代码行数:39,代码来源:GuiEntryPoint.java

示例7: initializeArgumentParser

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
private static ArgumentParser initializeArgumentParser() {
    final ArgumentParser parser = ArgumentParsers.newArgumentParser(PROGRAM_NAME);
    parser.addArgument(toArgName(ROUTERS_COUNT_DST))
            .type(Integer.class)
            .setDefault(1);
    parser.addArgument(toArgName(PEERS_COUNT_DST))
            .type(Integer.class)
            .setDefault(0);
    parser.addArgument(toArgName(PRE_POLICY_ROUTES_COUNT_DST))
            .type(Integer.class)
            .setDefault(0);
    parser.addArgument(toArgName(POST_POLICY_ROUTES_COUNT_DST))
            .type(Integer.class).setDefault(0);
    parser.addArgument(toArgName(PASSIVE_MODE_DST))
            .action(Arguments.storeTrue());
    parser.addArgument(toArgName(LOCAL_ADDRESS_DST))
            .type((parser13, arg, value) -> getInetSocketAddress(value, DEFAULT_LOCAL_PORT))
            .setDefault(LOCAL_ADDRESS);
    parser.addArgument("-ra", toArgName(REMOTE_ADDRESS_DST))
            .type((ArgumentTypeTool<List<InetSocketAddress>>) input ->
                    InetSocketAddressUtil.parseAddresses(input, DEFAULT_REMOTE_PORT))
            .setDefault(Collections.singletonList(REMOTE_ADDRESS));
    parser.addArgument(toArgName(LOG_LEVEL_DST))
            .type((parser1, arg, value) -> Level.toLevel(value))
            .setDefault(Level.INFO);
    return parser;
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:28,代码来源:BmpMockArguments.java

示例8: initializeArgumentParser

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
private static ArgumentParser initializeArgumentParser() {
    final ArgumentParser parser = ArgumentParsers.newArgumentParser(PROGRAM_NAME);

    parser.addArgument("-i", toArgName(ACTIVE_CONNECTION_PARAMETER)).type(Boolean.class)
            .setDefault(false).help(ACTIVE_CONNECTION_HELP);
    parser.addArgument("-ho", toArgName(HOLD_TIMER_PARAMETER)).type(Integer.class)
            .setDefault(INITIAL_HOLD_TIME).help(INITIAL_HOLD_TIME_HELP);
    parser.addArgument("-pr", toArgName(PREFIXES_PARAMETER)).type(Integer.class)
            .setDefault(0).help(PREFIXES_PARAMETER_HELP);
    parser.addArgument("-sc", toArgName(SPEAKERS_COUNT)).type(Integer.class)
            .setDefault(0).help(SPEAKERS_COUNT_HELP);
    parser.addArgument("-mp", toArgName(MULTIPATH_PARAMETER)).type(Boolean.class)
            .setDefault(false).help(MULTIPATH_PARAMETER_HELP);
    parser.addArgument("-" + AS_PARAMETER, toArgName(AS_PARAMETER))
            .type((ArgumentTypeTool<AsNumber>) as -> new AsNumber(Long.valueOf(as)))
            .setDefault(new AsNumber(64496L)).help(AS_PARAMETER_HELP);
    parser.addArgument("-ec", toArgName(EXTENDED_COMMUNITIES_PARAMETER))
            .type((ArgumentTypeTool<List<String>>) extComInput ->
                    Arrays.asList(extComInput.split(","))).setDefault(Collections.emptyList())
            .help(EXTENDED_COMMUNITIES_PARAMETER_HELP);
    parser.addArgument("-ll", toArgName(LOG_LEVEL))
            .type((ArgumentTypeTool<Level>) Level::toLevel).setDefault(Level.INFO).help("log levels");
    parser.addArgument("-ra", toArgName(REMOTE_ADDRESS_PARAMETER))
            .type((ArgumentTypeTool<List<InetSocketAddress>>) input ->
                    InetSocketAddressUtil.parseAddresses(input, DEFAULT_REMOTE_PORT))
            .setDefault(Collections.singletonList(REMOTE_ADDRESS))
            .help(REMOTE_ADDRESS_PARAMETER_HELP);
    parser.addArgument("-la", toArgName(LOCAL_ADDRESS_PARAMETER))
            .type((ArgumentTypeTool<InetSocketAddress>) input ->
                    getInetSocketAddress(input, DEFAULT_LOCAL_PORT))
            .setDefault(LOCAL_ADDRESS).help(LOCAL_ADDRESS_PARAMETER_HELP);
    return parser;
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:34,代码来源:Arguments.java

示例9: getParser

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
static ArgumentParser getParser() throws URISyntaxException {
    final ArgumentParser parser = ArgumentParsers.newArgumentParser("jar_file_name");
    parser.description("Validation Tool for Yang Models")
        .formatUsage();

    parser.addArgumentGroup("Required arguments")
        .addArgument("--yang-source-dir")
        .type(File.class)
        .required(true)
        .help("directory containing yang models which will be parsed")
        .dest("yang-source-dir")
        .metavar("");

    return parser;
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:16,代码来源:Params.java

示例10: main

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	// Parse and handle arguments
	ArgumentParser ap = ArgumentParsers.newArgumentParser("Distributed TPCH");
	ap.defaultHelp(true);
	ap.addArgument("-s", "--scale").setDefault(1.0).help("TPC H Scale (final Size in GB)").type(Double.class);
	ap.addArgument("-p","--parallelism").setDefault(1).help("Parallelism for program").type(Integer.class);
	ap.addArgument("-e", "--extension").setDefault(".csv").help("File extension for generated files");
	ap.addArgument("-o", "--outpath").setDefault("/tmp/").help("Output directory");
	
	Namespace ns = null;
       try {
           ns = ap.parseArgs(args);
       } catch (ArgumentParserException e) {
           ap.handleError(e);
           System.exit(1);
       }
	final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(ns.getInt("parallelism"));
	DistributedTPCH gen = new DistributedTPCH(env);
	gen.setScale(ns.getDouble("scale"));

	String base = ns.getString("outpath");
	String ext = ns.getString("extension");
	gen.generateParts().writeAsFormattedText(base + "parts" + ext, new TpchEntityFormatter());
	gen.generateLineItems().writeAsFormattedText(base + "lineitems" + ext, new TpchEntityFormatter());
	gen.generateOrders().writeAsFormattedText(base + "orders" + ext, new TpchEntityFormatter());
	gen.generateSuppliers().writeAsFormattedText(base + "suppliers" + ext, new TpchEntityFormatter());
	gen.generatePartSuppliers().writeAsFormattedText(base + "partsuppliers" + ext, new TpchEntityFormatter());
	gen.generateRegions().writeAsFormattedText(base + "regions" + ext, new TpchEntityFormatter());
	gen.generateNations().writeAsFormattedText(base + "nations" + ext, new TpchEntityFormatter());
	gen.generateCustomers().writeAsFormattedText(base + "customers" + ext, new TpchEntityFormatter());

	env.execute("Distributed TPCH Generator, Scale = "+gen.getScale());
}
 
开发者ID:project-flink,项目名称:flink-perf,代码行数:35,代码来源:TPCHGenerator.java

示例11: main

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
/**
 * The main() method is ignored in correctly deployed JavaFX application.
 * main() serves only as fallback in case the application can not be launched
 * through deployment artifacts, e.g., in IDEs with limited FX support.
 * NetBeans ignores main().
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
  optArgs = new Option();

  try {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("prog");
    parser.addArgument("--filename").required(false);
    parser.addArgument("--filesuonata").required(false);
    parser.parseArgs(args, optArgs);
  } catch (ArgumentParserException ex) {

  }
  launch(args);
}
 
开发者ID:abju,项目名称:SimulatoreCVS,代码行数:22,代码来源:CSVsimulator.java

示例12: runJolt

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:bazaarvoice,项目名称:jolt,代码行数:34,代码来源:JoltCli.java

示例13: createDefaultParser

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
protected static ArgumentParser createDefaultParser() {
	ArgumentParser parser = ArgumentParsers.newArgumentParser(command);

	parser.description("ifmapcli version " + DefaultConfig.IFMAP_CLI_VERSION);

	parser.defaultHelp(true);
	ParserUtil.addConnectionArgumentsTo(parser);
	ParserUtil.addCommonArgumentsTo(parser);

	return parser;
}
 
开发者ID:trustathsh,项目名称:ifmapcli,代码行数:12,代码来源:AbstractClient.java

示例14: main

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
    // Start cassandra if necessary (cassandra.yaml is provided)
    ArgumentParser parser = ArgumentParsers.newArgumentParser("java -jar emodb-web-local*.jar");
    parser.addArgument("server").required(true).help("server");
    parser.addArgument("emo-config").required(true).help("config.yaml - EmoDB's config file");
    parser.addArgument("emo-config-ddl").required(true).help("config-ddl.yaml - EmoDB's cassandra schema file");
    parser.addArgument("cassandra-yaml").nargs("?").help("cassandra.yaml - Cassandra configuration file to start an" +
            " in memory embedded Cassandra.");
    parser.addArgument("-z","--zookeeper").dest("zookeeper").action(Arguments.storeTrue()).help("Starts zookeeper");

    // Get the path to cassandraYaml or if zookeeper is available
    Namespace result = parser.parseArgs(args);
    String cassandraYaml = result.getString("cassandra-yaml");
    boolean startZk = result.getBoolean("zookeeper");

    String[] emoServiceArgs = args;

    // Start ZooKeeper
    TestingServer zooKeeperServer = null;
    if (startZk) {
        zooKeeperServer = isLocalZooKeeperRunning() ? null : startLocalZooKeeper();
        emoServiceArgs = (String[]) ArrayUtils.removeElement(args, "-z");
        emoServiceArgs = (String[]) ArrayUtils.removeElement(emoServiceArgs, "--zookeeper");

    }
    boolean success = false;


    if (cassandraYaml != null) {
        // Replace $DIR$ so we can correctly specify location during runtime
        File templateFile = new File(cassandraYaml);
        String baseFile = Files.toString(templateFile, Charset.defaultCharset());
        // Get the jar location
        String path = EmoServiceWithZK.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        String parentDir = new File(path).getParent();
        String newFile = baseFile.replace("$DATADIR$", new File(parentDir, "data").getAbsolutePath());
        newFile = newFile.replace("$COMMITDIR$", new File(parentDir, "commitlog").getAbsolutePath());
        newFile = newFile.replace("$CACHEDIR$", new File(parentDir, "saved_caches").getAbsolutePath());
        File newYamlFile = new File(templateFile.getParent(), "emo-cassandra.yaml");
        Files.write(newFile, newYamlFile, Charset.defaultCharset());

        startLocalCassandra(newYamlFile.getAbsolutePath());
        emoServiceArgs = (String[]) ArrayUtils.removeElement(emoServiceArgs, cassandraYaml);
    }

    try {
        EmoService.main(emoServiceArgs);
        success = true;

    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        // The main web server command returns immediately--don't stop ZooKeeper/Cassandra in that case.
        if (zooKeeperServer != null && !(success && args.length > 0 && "server".equals(args[0]))) {
            zooKeeperServer.stop();
            service.shutdown();
        }
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:60,代码来源:EmoServiceWithZK.java

示例15: main

import net.sourceforge.argparse4j.ArgumentParsers; //导入方法依赖的package包/类
public static void main(String[] args) {
  ArgumentParser argumentParser = ArgumentParsers.newArgumentParser("java solr-example.jar");

  Subparsers commandSubpersers =
      argumentParser.addSubparsers().title("Available Commands").metavar("COMMAND");

  Subparser addCmdSubParser = commandSubpersers.addParser("add").help("Add data to Solr.")
      .setDefault("command", new AddCommand());
  addCmdSubParser.addArgument("-s", "--solr-url")
      .help("Solr URL.\nExample: http://localhost:8983/solr/collection1");
  addCmdSubParser.addArgument("-z", "--zookeeper-host")
      .help("ZooKeeper host address.\nExample: localhost:2181");
  addCmdSubParser.addArgument("-r", "--zookeeper-chroot").setDefault("/solr")
      .help("ZooKeeper chroot.\nExample: /solr");
  addCmdSubParser.addArgument("-c", "--collection").setDefault("collection1")
      .help("Index collection name. Required if you use the -z parameter.\nExample: collection1");
  addCmdSubParser.addArgument("-d", "--data")
      .help("Document data formatted using JSON.\nExample: {\"id\":\"1\",\"title\":\"SolrJ\"}");

  Subparser deleteCmdSubParser = commandSubpersers.addParser("delete")
      .help("Delete data from Solr.").setDefault("command", new DeleteCommand());
  deleteCmdSubParser.addArgument("-s", "--solr-url")
      .help("Solr URL.\nExample: http://localhost:8983/solr/collection1");
  deleteCmdSubParser.addArgument("-z", "--zookeeper-host")
      .help("ZooKeeper host address.\nExample: localhost:2181");
  deleteCmdSubParser.addArgument("-r", "--zookeeper-chroot").setDefault("/solr")
      .help("ZooKeeper chroot.\nExample: /solr");
  deleteCmdSubParser.addArgument("-c", "--collection").setDefault("collection1")
      .help("Index collection name. Required if you use the -z parameter.\nExample: collection1");
  deleteCmdSubParser.addArgument("-u", "--unique-id")
      .help("Unique ID of the data to be deleted.\nExample: 1");

  Subparser searchCmdSubParser = commandSubpersers.addParser("search")
      .help("Search data of index.").setDefault("command", new SearchCommand());
  searchCmdSubParser.addArgument("-s", "--solr-url")
      .help("Solr URL.\nExample: http://localhost:8983/solr/collection1");
  searchCmdSubParser.addArgument("-z", "--zookeeper-host")
      .help("ZooKeeper host address.\nExample: localhost:2181");
  searchCmdSubParser.addArgument("-r", "--zookeeper-chroot").setDefault("/solr")
      .help("ZooKeeper chroot.\nExample: /solr");
  searchCmdSubParser.addArgument("-c", "--collection").setDefault("collection1")
      .help("Index collection name. Required if you use the -z parameter.\nExample: collection1");
  searchCmdSubParser.addArgument("-q", "--query")
      .help("Query to search index.\nExample: title:SolrJ");

  try {
    Namespace ns = argumentParser.parseArgs(args);
    Command command = ns.get("command");
    command.execute(ns.getAttrs());
  } catch (ArgumentParserException e) {
    argumentParser.handleError(e);
    System.exit(1);
  }
}
 
开发者ID:mosuka,项目名称:solrj-example,代码行数:55,代码来源:SolrJExampleCLI.java


注:本文中的net.sourceforge.argparse4j.ArgumentParsers.newArgumentParser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。