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


Java ArgumentParser.parseArgs方法代码示例

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


在下文中一共展示了ArgumentParser.parseArgs方法的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 = 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.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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	ArgumentParser parser = argParser();
	Namespace ns = null;
	try {
		ns = parser.parseArgs(args);
	} catch (ArgumentParserException e) {
		parser.handleError(e);
		System.exit(1);
	}

	String topicOrNull = ns.getString(TOPIC);
	String zookeeper = ns.getString(ZOOKEEPER);
	boolean rackAware = ns.getBoolean(RACK_AWARE);

	BrokersTopicsCache.initialize(zookeeper, rackAware);
	String assignmentPlanJsonStr = generateAssignmentPlan(ns, topicOrNull, rackAware);

	switch (ns.getString(OPERATION)) {
	case GENERATE:
		break;
	case EXECUTE:
		if (assignmentPlanJsonStr != null) {
			executePlan(zookeeper, assignmentPlanJsonStr);
		} else {
			log.info("No assignment plan generated to execute, exiting");
		}
		break;
	default:
		throw new ReplicaAssignmentException("Unknown mode: " + ns.getString(OPERATION));
	}
}
 
开发者ID:flipkart-incubator,项目名称:kafka-balancer,代码行数:32,代码来源:KafkaBalancerMain.java

示例10: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //导入方法依赖的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

示例11: createFromArgs

import net.sourceforge.argparse4j.inf.ArgumentParser; //导入方法依赖的package包/类
public static VerifiableConsumer createFromArgs(ArgumentParser parser, String[] args) throws ArgumentParserException {
    Namespace res = parser.parseArgs(args);

    String topic = res.getString("topic");
    boolean useAutoCommit = res.getBoolean("useAutoCommit");
    int maxMessages = res.getInt("maxMessages");
    boolean verbose = res.getBoolean("verbose");
    String configFile = res.getString("consumer.config");

    Properties consumerProps = new Properties();
    if (configFile != null) {
        try {
            consumerProps.putAll(Utils.loadProps(configFile));
        } catch (IOException e) {
            throw new ArgumentParserException(e.getMessage(), parser);
        }
    }

    consumerProps.put(ConsumerConfig.GROUP_ID_CONFIG, res.getString("groupId"));
    consumerProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, res.getString("brokerList"));
    consumerProps.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, useAutoCommit);
    consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, res.getString("resetPolicy"));
    consumerProps.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, Integer.toString(res.getInt("sessionTimeout")));
    consumerProps.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG, res.getString("assignmentStrategy"));

    StringDeserializer deserializer = new StringDeserializer();
    KafkaConsumer<String, String> consumer = new KafkaConsumer<>(consumerProps, deserializer, deserializer);

    return new VerifiableConsumer(
            consumer,
            System.out,
            topic,
            maxMessages,
            useAutoCommit,
            false,
            verbose);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:38,代码来源:VerifiableConsumer.java

示例12: parseArgs

import net.sourceforge.argparse4j.inf.ArgumentParser; //导入方法依赖的package包/类
/**
 * Parse the input arguments and return the {@link Namespace} object.
 * @param args the input argument list
 * @return the parsed arguments as a {@link Namespace} object
 */
private static Namespace parseArgs(String[] args) {
	ArgumentParser parser = ArgumentParsers.newArgumentParser("Align")
			.defaultHelp(true)
			.description("Calculate the alignment of multiple structures");
	parser.addArgument("-a", "--align")
	.choices(CeCPMain.algorithmName, FatCatRigid.algorithmName, "DUMMY").setDefault(FatCatRigid.algorithmName)
	.help("Specify alignment method");
	parser.addArgument("-s", "--score")
	.choices("TM","RMSD").setDefault("TM")
	.help("Specify scoring method");
	parser.addArgument("-u", "--files").type(Boolean.class)
	.setDefault(false);
	parser.addArgument("-k", "--numclusts")
	.help("The number of clusters").setDefault(2);
	parser.addArgument("-c", "--cluster")
	.choices("PIC").setDefault("PIC")
	.help("Specify clustering method");
	parser.addArgument("pdbId").nargs("*")
	.help("The PDB Ids to consider");
	parser.addArgument("-z", "--sample").type(Double.class)
	.help("The sample of the PDB to take").setDefault(1.00);
	parser.addArgument("-l", "--minlength").type(Double.class)
	.help("The minimum length of each chain").setDefault(60);
	parser.addArgument("-t", "--threshold").type(Double.class)
	.help("The threshold to define an edge").setDefault(0.5);
	parser.addArgument("-f", "--hadoop")
	.help("The hadoop file to read from").setDefault(defaultPath);
	Namespace ns = null;
	try {
		ns = parser.parseArgs(args);
	} catch (ArgumentParserException e) {
		parser.handleError(e);
		System.exit(1);
	}
	return ns;
}
 
开发者ID:biojava,项目名称:biojava-spark,代码行数:42,代码来源:ChainAligner.java

示例13: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //导入方法依赖的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

示例14: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //导入方法依赖的package包/类
public static void main(String[] args) {
    ArgumentParser parser = ArgumentParsers.newArgumentParser("com.flurry.proguard.UploadMapping", true)
            .description("Uploads Proguard/Native Mapping Files for Android");
    parser.addArgument("-k", "--api-key").required(true)
                .help("API Key for your project");
    parser.addArgument("-u", "--uuid").required(true)
                .help("The build UUID");
    parser.addArgument("-p", "--path").required(true)
            .help("Path to ProGuard/Native mapping file for the build");
    parser.addArgument("-t", "--token").required(true)
                .help("A Flurry auth token to use for the upload");
    parser.addArgument("-to", "--timeout").type(Integer.class).setDefault(TEN_MINUTES_IN_MS)
                .help("How long to wait (in ms) for the upload to be processed");
    parser.addArgument("-n", "--ndk").type(Boolean.class).setDefault(false)
                .help("Is it a Native mapping file");

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

    EXIT_PROCESS_ON_ERROR = true;
    if (res.getBoolean("ndk")) {
        uploadFiles(res.getString("api_key"), res.getString("uuid"),
                new ArrayList<>(Collections.singletonList(res.getString("path"))),
                res.getString("token"), res.getInt("timeout"), AndroidUploadType.ANDROID_NATIVE);
    } else {
        uploadFiles(res.getString("api_key"), res.getString("uuid"),
                new ArrayList<>(Collections.singletonList(res.getString("path"))),
                res.getString("token"), res.getInt("timeout"), AndroidUploadType.ANDROID_JAVA);
    }
}
 
开发者ID:flurry,项目名称:upload-clients,代码行数:36,代码来源:UploadMapping.java

示例15: main

import net.sourceforge.argparse4j.inf.ArgumentParser; //导入方法依赖的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


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