本文整理汇总了Java中net.sourceforge.argparse4j.ArgumentParsers类的典型用法代码示例。如果您正苦于以下问题:Java ArgumentParsers类的具体用法?Java ArgumentParsers怎么用?Java ArgumentParsers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArgumentParsers类属于net.sourceforge.argparse4j包,在下文中一共展示了ArgumentParsers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadFromCLI
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的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: getArgumentParser
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的package包/类
static ArgumentParser getArgumentParser() {
ArgumentParser parser = ArgumentParsers.newArgumentParser("dockerfile-image-update", true)
.description("Image Updates through Pull Request Automator");
parser.addArgument("-o", "--org")
.help("search within specific organization (default: all of github)");
/* Currently, because of argument passing reasons, you can only specify one branch. */
parser.addArgument("-b", "--branch")
.help("make pull requests for given branch name (default: master)");
parser.addArgument("-g", "--" + Constants.GIT_API)
.help("link to github api; overrides environment variable");
parser.addArgument("-f", "--auto-merge").action(Arguments.storeTrue())
.help("NOT IMPLEMENTED / set to automatically merge pull requests if available");
parser.addArgument("-m")
.help("message to provide for pull requests");
parser.addArgument("-c")
.help("additional commit message for the commits in pull requests");
return parser;
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: main
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的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);
}
}
示例7: main
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的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);
}
}
示例8: main
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的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"));
}
示例9: handleArguments
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的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;
}
示例10: parseArgs
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的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;
}
示例11: MitMSOCKS4J
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的package包/类
public MitMSOCKS4J() {
parser = ArgumentParsers.newArgumentParser("mitmsocks4j").description("Strips SSL/TLS layer from SOCKS proxy connection to dump plain data!");
parser.addArgument("-l", "--loglevel").required(false).nargs("?").choices("ALL", "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "OFF")
.help("Sets logging level!").setDefault("OFF");
parser.addArgument("-x", "--proxyport").required(false).nargs("?").help("Proxy port that proxy listens.(default:" + DEFAULT_PROXY_PORT + ")")
.type(Integer.class).setDefault(DEFAULT_PROXY_PORT);
parser.addArgument("-d", "--delegatorport").required(false).nargs("?")
.help("Delegator port that mitm takes place.(default:" + DEFAULT_DELEGATOR_PORT + ")").type(Integer.class).setDefault(DEFAULT_DELEGATOR_PORT);
parser.addArgument("-s", "--securedports").required(false).nargs("*").help("Secured ports that will be ssl-stripped").type(Integer.class)
.setDefault(FeatureControl.SUPPRESS);
parser.addArgument("-k", "--keystore").required(false).help("Keystore that will be used to imitate actual server certificates for clients(default:"+DEFAULT_KEYSTORE+")")
.setDefault(DEFAULT_KEYSTORE);
parser.addArgument("-p", "--password").required(false).help("Keystore password.(default:"+DEFAULT_PASSWORD+")").setDefault(DEFAULT_PASSWORD);
}
示例12: 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);
}
}
示例13: getArgumentParser
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的package包/类
@Provides
@Singleton
ArgumentParser getArgumentParser(@Named("app-name") String appName,
@Named("url-key") String urlKey) {
ArgumentParser argumentParser = ArgumentParsers.newArgumentParser(appName)
.defaultHelp(true)
.description("Downloads HLS/M3U/M3U8 streams and combines them using ffmpeg.")
.epilog("For additional questions and help, refer to https://github.com/TheGoodlike13/hls-downloader");
argumentParser.addArgument("url").nargs("+")
.dest(urlKey)
.help(URL_EXPLANATION);
return argumentParser;
}
示例14: parseArgs
import net.sourceforge.argparse4j.ArgumentParsers; //导入依赖的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;
}
示例15: 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));
}