當前位置: 首頁>>代碼示例>>Java>>正文


Java ArgumentParser類代碼示例

本文整理匯總了Java中net.sourceforge.argparse4j.inf.ArgumentParser的典型用法代碼示例。如果您正苦於以下問題:Java ArgumentParser類的具體用法?Java ArgumentParser怎麽用?Java ArgumentParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ArgumentParser類屬於net.sourceforge.argparse4j.inf包,在下文中一共展示了ArgumentParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadFromCLI

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
/**
 * Reads a configuration file from the passed CLI args
 *
 * @return Path to config file, or exception
 * @throws ConfigParseException if arguments were incorrectly specified, or nothing was passed (in which case it will print "usage" details)
 */
public static String loadFromCLI(String programName, String... args) throws ConfigParseException {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("java -jar " + programName + "-[VERSION].jar").defaultHelp(true);
    parser.addArgument("--config").metavar("/path/to/app-config.json").required(true).help("Path to configuration file");

    try {
        // parse CLI args and return config file
        Namespace cli = parser.parseArgs(args);
        return cli.getString("config");

    } catch (ArgumentParserException e) {
        // show help message and stop execution
        parser.handleError(e);
        throw new ConfigParseException(e);
    }
}
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:22,代碼來源:AppConfigFileLoader.java

示例2: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
public static void main(String[] args) {
    ArgumentParser parser = argParser();
    if (args.length == 0) {
        parser.printHelp();
        Exit.exit(0);
    }

    try {
        final VerifiableConsumer consumer = createFromArgs(parser, args);
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                consumer.close();
            }
        });

        consumer.run();
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        Exit.exit(1);
    }
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:23,代碼來源:VerifiableConsumer.java

示例3: run

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
@Override
public void run(final ArgumentParser parser, final Argument arg, final Map<String, Object> attrs, final String flag, final Object value) throws ArgumentParserException {
    @SuppressWarnings("unchecked")
    final String paramValues = ((List<String>) value).get(0);
    final Set<String> unique = new HashSet<>(Arrays.asList(paramValues.split(",")));
    final String[] protocols = unique.toArray(new String[unique.size()]);

    if (!(protocols.length == 1 && protocols[0].equals("all"))) {
        for (final String protocol : protocols) {
            if (!(protocol.equals("ipv4") || protocol.equals("udp") || protocol.equals("icmp"))) {
                throw new ArgumentParserException("invalid protocol: " + protocol, parser, arg);
            }
        }
    }

    attrs.put(arg.getDest(), new ArrayList<String>(Arrays.asList(protocols)));
}
 
開發者ID:NCSC-NL,項目名稱:PEF,代碼行數:18,代碼來源:ChecksumCheckAction.java

示例4: run

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
@Override
public void run(final ArgumentParser parser, final Argument arg,
                final Map<String, Object> attrs, final String flag, final Object value) throws ArgumentParserException {
    @SuppressWarnings("unchecked")
    final List<String> values = (List<String>) value;

    final String key = values.get(0);
    if (key.length() != 32 || !Util.stringNumInRadix(key, 16)) {
        throw new ArgumentParserException("AES key must be a 32 character hexidecimal string (128-bit)", parser, arg);
    }

    final String maskString = values.get(1);
    final String maskValueString = maskString.substring(1);

    if (!maskString.startsWith("/") || !Util.stringNumInRadix(maskValueString, 10)) {
        throw new ArgumentParserException("IPv6 mask must be an integer prefixed with /", parser, arg);
    }

    final int mask = Integer.parseInt(maskValueString);
    if (mask < 0 || mask > 120) {
        throw new ArgumentParserException("IPv6 mask must be in range [0, 120]", parser, arg);
    }

    attrs.put(arg.getDest(), value);
}
 
開發者ID:NCSC-NL,項目名稱:PEF,代碼行數:26,代碼來源:Pseudo6CheckAction.java

示例5: run

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
@Override
public void run(final ArgumentParser parser, final Argument arg,
                final Map<String, Object> attrs, final String flag, final Object value) throws ArgumentParserException {
    @SuppressWarnings("unchecked")
    final List<String> values = (List<String>) value;

    final String key = values.get(0);
    if (key.length() != 32 || !Util.stringNumInRadix(key, 16)) {
        throw new ArgumentParserException("AES key must be a 32 character hexidecimal string (128-bit)", parser, arg);
    }

    final String maskString = values.get(1);
    final String maskValueString = maskString.substring(1);

    if (!maskString.startsWith("/") || !Util.stringNumInRadix(maskValueString, 10)) {
        throw new ArgumentParserException("IPv4 mask must be an integer prefixed with /", parser, arg);
    }

    final int mask = Integer.parseInt(maskValueString);
    if (mask < 0 || mask > 24) {
        throw new ArgumentParserException("IPv4 mask must be in range [0, 24]", parser, arg);
    }

    attrs.put(arg.getDest(), value);
}
 
開發者ID:NCSC-NL,項目名稱:PEF,代碼行數:26,代碼來源:Pseudo4CheckAction.java

示例6: run

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
@Override
public void run(ArgumentParser parser, Argument arg,
                Map<String, Object> attrs, String flag, Object value)
    throws ArgumentParserException {
  try {
    attrs.put(arg.getDest(),
              ParameterUtil.parseDateHour(value.toString()));
  } catch (DateTimeParseException dateHourException) {
    try {
      attrs.put(arg.getDest(),
                ParameterUtil.parseDate(value.toString()));
    } catch (Exception dateException) {
      throw new ArgumentParserException(
          String.format(
              "could not parse date/datehour for parameter '%s'; if datehour: [%s], if date: [%s]",
              arg.textualName(), dateHourException.getMessage(), dateException.getMessage()),
          parser);
    }
  }
}
 
開發者ID:spotify,項目名稱:styx,代碼行數:21,代碼來源:CliMain.java

示例7: doMain

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的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

示例8: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的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

示例9: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的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

示例10: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
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);
    }
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:25,代碼來源:ImpressionsToInfluxDb.java

示例11: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
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);
    }
}
 
開發者ID:SeldonIO,項目名稱:seldon-server,代碼行數:24,代碼來源:PredictionsToInfluxDb.java

示例12: verifyZKStructure

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
private static void verifyZKStructure(Options opts, ArgumentParser parser) throws ArgumentParserException {
  if (opts.zkHost != null) {
    assert opts.collection != null;
    ZooKeeperInspector zki = new ZooKeeperInspector();
    try {
      opts.shardUrls = zki.extractShardUrls(opts.zkHost, opts.collection);
    } catch (Exception e) {
      LOG.debug("Cannot extract SolrCloud shard URLs from ZooKeeper", e);
      throw new ArgumentParserException(e, parser);
    }
    assert opts.shardUrls != null;
    if (opts.shardUrls.size() == 0) {
      throw new ArgumentParserException("--zk-host requires ZooKeeper " + opts.zkHost
        + " to contain at least one SolrCore for collection: " + opts.collection, parser);
    }
    opts.shards = opts.shardUrls.size();
    LOG.debug("Using SolrCloud shard URLs: {}", opts.shardUrls);
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:20,代碼來源:MapReduceIndexerTool.java

示例13: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
public static void main(String[] args) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("AdlChecker")
            .defaultHelp(true)
            .description("Checks the syntax of ADL files");

    parser.addArgument("file").nargs("*")
            .help("File to calculate checksum");

    Namespace ns = null;
    try {
        ns = parser.parseArgs(args);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }

    if(ns.getList("file").isEmpty()) {
        parser.printUsage();
        parser.printHelp();
    }

    validateArchetypes(ns.getList("file"));
}
 
開發者ID:nedap,項目名稱:archie,代碼行數:24,代碼來源:AdlChecker.java

示例14: handleArguments

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
public Option handleArguments(String argv[]) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("Detector")
            .defaultHelp(true)
            .description("Convert Zawgyi <-> Unicode encodings.");

    parser.addArgument("-t", "--to")
            .choices("zawgyi", "unicode")
            .required(true)
            .help("Specify hash function to use");

    parser.addArgument("files").nargs("*")
            .help("Files to convert");

    try {
        parser.parseArgs(argv, this);
    } catch (ArgumentParserException e) {
        parser.handleError(e);
        System.exit(1);
    }

    return this;
}
 
開發者ID:htooaunghlaing,項目名稱:NyaungUConverter,代碼行數:23,代碼來源:PaytanConverter.java

示例15: parseArgs

import net.sourceforge.argparse4j.inf.ArgumentParser; //導入依賴的package包/類
private static Namespace parseArgs(String[] args) {
	ArgumentParser parser =
	        ArgumentParsers.newArgumentParser("moco", false).description("The Monty compiler.").epilog(
	                "Without -S or -c the program is compiled and directly executed.");

	parser.addArgument("--help").action(Arguments.help()).help("Print this help and exit.");
	parser.addArgument("-S", "--emit-assembly").action(Arguments.storeTrue()).dest("emitAssembly").help(
	        "Emit the LLVM assembly and stop.");
	parser.addArgument("-c", "--compile-only").action(Arguments.storeTrue()).dest("compileOnly").help(
	        "Only compile the executable without running it.");
	parser.addArgument("-e", "--stop-on-first-error").action(Arguments.storeTrue()).dest("stopOnFirstError").help(
	        "Stop the compilation on the first encountered error.");
	parser.addArgument("-p", "--print-ast").action(Arguments.storeTrue()).dest("printAST").help("Print the AST.");
	parser.addArgument("-d", "--debug-parsetree").action(Arguments.storeTrue()).dest("debugParseTree").help(
	        "Debug the parsetree without running anything.");
	parser.addArgument("-o").metavar("<file>").dest("outputFile").help("Write output to <file>.");
	parser.addArgument("file").nargs("?").help("Monty file to run.");

	Namespace ns = null;
	try {
		ns = parser.parseArgs(args);
	} catch (ArgumentParserException ape) {
		parser.handleError(ape);
	}
	return ns;
}
 
開發者ID:MontysCoconut,項目名稱:moco,代碼行數:27,代碼來源:Main.java


注:本文中的net.sourceforge.argparse4j.inf.ArgumentParser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。