本文整理匯總了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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"));
}
示例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;
}
示例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;
}
示例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));
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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));
}
示例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);
}
}
示例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);
}