本文整理了Java中net.sourceforge.argparse4j.inf.ArgumentParser.parseArgsOrFail()
方法的一些代码示例,展示了ArgumentParser.parseArgsOrFail()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArgumentParser.parseArgsOrFail()
方法的具体详情如下:
包路径:net.sourceforge.argparse4j.inf.ArgumentParser
类名称:ArgumentParser
方法名:parseArgsOrFail
[英]Parses command line arguments, handling any errors.
This is a shortcut method that combines #parseArgs and #handleError. If the arguments can be successfully parsed, the resulted attributes are returned as a Namespace object. Otherwise, the program exits with a 1
return code.
[中]解析命令行参数,处理任何错误。
这是一种结合了#parseArgs和#handleError的快捷方法。如果可以成功解析参数,则结果属性将作为命名空间对象返回。否则,程序将以1
返回代码退出。
代码示例来源:origin: bazaarvoice/emodb
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);
}
}
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.earcomparer
public static void main(String[] args) {
ArgumentParser argParser = ArgumentParsers.newArgumentParser("EAR Version Extractor", true, "-")
.description("Extracts version from ear files in given directory.");
argParser.addArgument("-directory").type(String.class).required(true).help("Path to directory with ears");
argParser.addArgument("-out").choices("LIST", "FILES").required(true).help("Output type - LIST or FILES");
Namespace res = argParser.parseArgsOrFail(args);
String directory = res.get("directory");
String out = res.getString("out");
List<T.V2<Path, String>> output = new FileSearcher().searchFiles(Paths.get(directory), "glob:**/*.ear", false).
stream().parallel().
map(p -> getVersionFromEAR(p)).
collect(Collectors.toList());
if ("LIST".equals(out)) {
output.forEach(v -> System.out.println(v.getA().getFileName() + "\t" + v.getB()));
}
else {
output.forEach(v -> {
Path versionPath = Paths.get(v.getA().toString().replace(".ear", ".version"));
try(FileWriter ww = new FileWriter(versionPath.toFile()); BufferedWriter w = new BufferedWriter(ww)) {
w.write(v.getB());
} catch(IOException e) {
throw new RuntimeException("Could not write version to file: " + v.getA(), e);
}
});
}
}
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.earcomparer
public static void main(String[] args) {
try {
ArgumentParser argParser = ArgumentParsers.newArgumentParser("EAR Comparer", true, "-")
.description("Compares two EAR files . Returns 0 when ear are equal, 1 when ear are different, on error 2");
argParser.addArgument("-old").type(String.class).required(true).help("Path to old ear. Ex: T:/Source/R160729/AP_API_IO.ear");
argParser.addArgument("-new").type(String.class).required(true).help("Path to new ear. Ex: T:/Source/R160924/AP_API_IO.ear");
argParser.addArgument("-verbose").type(String.class).required(false).help("Quiet output");
Namespace res = argParser.parseArgsOrFail(args);
String oldPath = res.get("old");
String newPath = res.get("new");
String verbose = res.get("verbose");
List<CompareResult> result = new EARComparer().compare(Paths.get(oldPath), Paths.get(newPath));
result.forEach(r -> System.out.println(r));
if (result.size() == 0) {
if (!"quiet".equals(verbose)) {
System.out.println("No difference between: " + oldPath + " and " + newPath);
}
System.exit(0);
}
else {
System.exit(1);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(2);
}
}
}
代码示例来源:origin: stanford-futuredata/macrobase
public static void main(String... args) throws IOException {
ArgumentParser parser = ArgumentParsers.newFor("MacroBase SQL").build()
.defaultHelp(true)
.description("Run MacroBase SQL.");
parser.addArgument("-f", "--file").help("Load file with SQL queries to execute");
parser.addArgument("-p", "--paging").type(Arguments.booleanType()).setDefault(false)
.help("Turn on paging of results for SQL queries");
final Namespace parsedArgs = parser.parseArgsOrFail(args);
final MacroBaseSQLRepl repl = new MacroBaseSQLRepl(parsedArgs.get("paging"));
final String asciiArt = Resources
.toString(Resources.getResource(ASCII_ART_FILE), Charsets.UTF_8);
boolean printedWelcome = false;
if (parsedArgs.get("file") != null) {
System.out.println(asciiArt);
printedWelcome = true;
final String queriesFromFile = Files
.toString(new File((String) parsedArgs.get("file")), Charsets.UTF_8);
repl.executeQueries(queriesFromFile, true);
}
if (!printedWelcome) {
System.out.println(asciiArt);
}
repl.runRepl();
}
}
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.earcomparer
argParser.addArgument("-tibcohome").type(String.class).required(false).help("Path to tibco home. Ex: T:/tib/app/tibco");
Namespace res = argParser.parseArgsOrFail(args);
try {
Path prefFilePath = Paths.get((String)res.get("prefs"));
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.earcomparer
public static void main(String[] args) {
ArgumentParser argParser = ArgumentParsers.newArgumentParser("EAR Version Updater", true, "-")
.description("Updates version in ear files in given directory.");
argParser.addArgument("-directory").type(String.class).required(true).help("Path to directory with ears");
argParser.addArgument("-version").type(String.class).required(true).help("Version that will be written in Tibco.xml");
Namespace res = argParser.parseArgsOrFail(args);
String directory = res.get("directory");
String version = res.getString("version");
new FileSearcher().searchFiles(Paths.get(directory), "glob:**/*.ear", false).
stream().parallel().
map(p -> T.V(p, new LoadZipFile().load(p))).
map(v -> T.V(v.getA(), getVersion(v), v.getB())).
filter(v -> v.getB().isPresent()).
map(v -> T.V(v.getA(), new XmlBuilderFactory().parseDocument(new ByteArrayInputStream(v.getB().get().getB())), v.getB(), v.getC())).
forEach(v -> {
v.getB().search("version").forEach(vnode -> {
System.out.println(v.getA() + " " + vnode.getTextContent() + " -> " + version);
vnode.setTextContent(version);
});
byte[] bytes = v.getB().toString().getBytes();
V3<String, byte[], ZipEntry> zipFileEntry = v.getC().get();
zipFileEntry.setB(bytes);
new LoadZipFile().updateFile(v.getA(), v.getD());
});
}
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.earcomparer
public static void main(String[] args) {
ArgumentParser argParser = ArgumentParsers.newArgumentParser("Tibco passwords de/encryptor", true, "-")
.description("Encrypts or decrypts Tibco password from fullConfigs");
argParser.addArgument("-action").choices(ENCRYPT, DECRYPT).required(true).help("What to do - encrypt or decrypt. Ex: decrypt");
argParser.addArgument("-password").type(String.class).required(true).help("Password string to be encrypted or decrypted. Ex: #!St7Uzipt4y6Od6iTLGNtwSUiLk00LuMB");
Namespace res = argParser.parseArgsOrFail(args);
String action = res.getString("action");
String password = res.getString("password");
switch (action) {
case ENCRYPT: System.out.println(new PasswordDecrypter().encrypt(password));
break;
case DECRYPT: System.out.println(new PasswordDecrypter().decrypt(password));
break;
}
}
}
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.earcomparer
public static void main(String[] args) {
ArgumentParser argParser = ArgumentParsers.newArgumentParser("Config normalizer", true, "-")
.description("Normalizes full config XML - orders elements");
argParser.addArgument("-config").type(String.class).required(true).help("Path to config. Ex: T:/Source/R160729/AP_API_IO_TST1.xml");
argParser.addArgument("-out").type(String.class).required(false).help("Path to config. Ex: T:/Source/R160729/AP_API_IO_TST1.xml");
argParser.addArgument("-tibcohome").type(String.class).required(false).help("Path to tibco home. Ex: T:/tib/app/tibco");
Namespace res = argParser.parseArgsOrFail(args);
Path config = Paths.get(res.getString("config"));
Path outPath = null;
Path tibcoHome = Paths.get(res.getString("tibcohome") == null ? "t:/tib/app/tibco" : res.getString("tibcohome"));
SDKPropertiesLoader loader = new SDKPropertiesLoader(tibcoHome);
if (res.get("out") != null) {
outPath = Paths.get(res.getString("out"));
}
NodeBuilder out = new NormalizeConfig(loader).loadFullConfig(config, true);
if (outPath != null) new XmlBuilderFactory().renderNode(out, outPath);
else System.out.println(out);
}
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.earcomparer
Namespace res = argParser.parseArgsOrFail(args);
try {
String oldPath = res.get("old");
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.earcomparer
argParser.addArgument("-earmask").type(String.class).required(false).help("EAR mask - restricts comparing only for given mask. Ex: *");
Namespace res = argParser.parseArgsOrFail(args);
Path deployed = Paths.get(res.getString("deployed"));
Path built = Paths.get(res.getString("built"));
代码示例来源:origin: io.github.jiri-meluzin/io.github.jiri-meluzin.tibcobwutils.earcomparer
argParser.addArgument("-verbose").action(verboseAction).setDefault(Arguments.SUPPRESS).help("Sets verbose mode - more info in case of errors.");
Namespace res = argParser.parseArgsOrFail(args);
内容来源于网络,如有侵权,请联系作者删除!