本文整理汇总了Java中net.sourceforge.argparse4j.inf.Argument类的典型用法代码示例。如果您正苦于以下问题:Java Argument类的具体用法?Java Argument怎么用?Java Argument使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Argument类属于net.sourceforge.argparse4j.inf包,在下文中一共展示了Argument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的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)));
}
示例2: run
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的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);
}
示例3: run
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的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);
}
示例4: run
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的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);
}
}
}
示例5: run
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
@Override
public void run(ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag, Object value) throws ArgumentParserException {
Path path = Paths.get(value.toString());
if (!Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
throw new ArgumentParserException("cannot find directory " + path, parser, arg);
}
attrs.put(arg.getDest(), value);
}
示例6: run
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
@Override
public void run(final ArgumentParser parser, final Argument arg, final Map<String, Object> attrs, final String flag, final Object value) throws ArgumentParserException {
final File file = new File(value.toString());
if (!file.isFile()) {
throw new ArgumentParserException("cannot find file " + file, parser, arg);
}
attrs.put(arg.getDest(), value);
}
示例7: createArgumentParser
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
private ArgumentParser createArgumentParser(Config config) {
this.allArguments = new HashMap<String, Argument>();
ArgumentParser parser = ArgumentParsers.newArgumentParser("jasperstarter", false, "-", "@")
.version(config.getVersionString());
//ArgumentGroup groupOptions = parser.addArgumentGroup("options");
parser.addArgument("-h", "--help").action(Arguments.help()).help("show this help message and exit");
parser.addArgument("--locale").dest(Dest.LOCALE).metavar("<lang>")
.help("set locale with two-letter ISO-639 code"
+ " or a combination of ISO-639 and ISO-3166 like de_DE");
parser.addArgument("-v", "--verbose").dest(Dest.DEBUG).action(Arguments.storeTrue()).help("display additional messages");
parser.addArgument("-V", "--version").action(Arguments.version()).help("display version information and exit");
Subparsers subparsers = parser.addSubparsers().title("commands").
help("type <cmd> -h to get help on command").metavar("<cmd>").
dest(Dest.COMMAND);
Subparser parserCompile =
subparsers.addParser("compile", true).aliases("cp")
.help("compile reports");
createCompileArguments(parserCompile);
Subparser parserProcess =
subparsers.addParser("process", true).aliases("pr")
.help("view, print or export an existing report");
createProcessArguments(parserProcess);
Subparser parserListPrinters =
subparsers.addParser("list_printers", true).aliases("printers", "lpr")
.help("lists available printers");
Subparser parserListParams =
subparsers.addParser("list_parameters", true).aliases("params", "lpa").
help("list parameters from a given report");
createListParamsArguments(parserListParams);
return parser;
}
示例8: run
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
@Override
public abstract void run(ArgumentParser parser, Argument arg, Map<String, Object> attrs, String flag, Object value) throws ArgumentParserException;
示例9: onAttach
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
@Override
public void onAttach(final Argument arg) {
}
示例10: onAttach
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
@Override
public void onAttach(Argument arg) {
}
示例11: addURLArgument
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
protected Argument addURLArgument(Subparser subparser) {
return subparser.addArgument("url")
.help("URL to be tested");
}
示例12: createProcessArguments
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
private void createProcessArguments(Subparser parser) {
ArgumentGroup groupOptions = parser.addArgumentGroup("options");
groupOptions.addArgument("-f").metavar("<fmt>").dest(Dest.OUTPUT_FORMATS).
required(true).nargs("+").type(Arguments.enumType(OutputFormat.class)).
help("view, print, pdf, rtf, xls, xlsMeta, xlsx, docx, odt, ods, pptx, csv, csvMeta, html, xhtml, xml, jrprint");
groupOptions.addArgument("input").metavar("<input>").dest(Dest.INPUT).required(true).help("input file (.jrxml|.jasper|.jrprint)");
groupOptions.addArgument("-o").metavar("<output>").dest(Dest.OUTPUT).help("directory or basename of outputfile(s)");
//groupOptions.addArgument("-h", "--help").action(Arguments.help()).help("show this help message and exit");
ArgumentGroup groupCompileOptions = parser.addArgumentGroup("compile options");
groupCompileOptions.addArgument("-w", "--write-jasper").
dest(Dest.WRITE_JASPER).action(Arguments.storeTrue()).help("write .jasper file to imput dir if jrxml is processed");
ArgumentGroup groupFillOptions = parser.addArgumentGroup("fill options");
groupFillOptions.addArgument("-a").metavar("<filter>").dest(Dest.ASK)
.type(Arguments.enumType(AskFilter.class)).nargs("?")
.setConst(AskFilter.p)
.help("ask for report parameters. Filter: a, ae, u, ue, p, pe"
+ " (see usage)");
groupFillOptions.addArgument("-P").metavar("<param>").dest(Dest.PARAMS)
.nargs("+").help(
"report parameter: name=value [...]");
groupFillOptions.addArgument("-r").metavar("<resource>").dest(Dest.RESOURCE)
.nargs("?").setConst("").help(
"path to report resource dir or jar file. If <resource> is not"
+ " given the input directory is used.");
ArgumentGroup groupDatasourceOptions = parser.addArgumentGroup("datasource options");
groupDatasourceOptions.addArgument("-t").metavar("<dstype>").dest(Dest.DS_TYPE).
required(false).type(Arguments.enumType(DsType.class)).setDefault(DsType.none).
help("datasource type: none, csv, xml, json, mysql, postgres, oracle, generic (jdbc)");
Argument argDbHost = groupDatasourceOptions.addArgument("-H").metavar("<dbhost>").dest(Dest.DB_HOST).help("database host");
Argument argDbUser = groupDatasourceOptions.addArgument("-u").metavar("<dbuser>").dest(Dest.DB_USER).help("database user");
Argument argDbPasswd = groupDatasourceOptions.addArgument("-p").metavar("<dbpasswd>").dest(Dest.DB_PASSWD).setDefault("").help("database password");
Argument argDbName = groupDatasourceOptions.addArgument("-n").metavar("<dbname>").dest(Dest.DB_NAME).help("database name");
Argument argDbSid = groupDatasourceOptions.addArgument("--db-sid").metavar("<sid>").dest(Dest.DB_SID).help("oracle sid");
Argument argDbPort = groupDatasourceOptions.addArgument("--db-port").metavar("<port>").dest(Dest.DB_PORT).type(Integer.class).help("database port");
Argument argDbDriver = groupDatasourceOptions.addArgument("--db-driver").metavar("<name>").dest(Dest.DB_DRIVER).help("jdbc driver class name for use with type: generic");
Argument argDbUrl = groupDatasourceOptions.addArgument("--db-url").metavar("<jdbcUrl>").dest(Dest.DB_URL).help("jdbc url without user, passwd with type:generic");
groupDatasourceOptions.addArgument("--jdbc-dir").metavar("<dir>").dest(Dest.JDBC_DIR).type(File.class).help("directory where jdbc driver jars are located. Defaults to ./jdbc");
Argument argDataFile = groupDatasourceOptions.addArgument("--data-file").metavar("<file>").dest(Dest.DATA_FILE).type(File.class).help("input file for file based datasource");
groupDatasourceOptions.addArgument("--csv-first-row").metavar("true", "false").dest(Dest.CSV_FIRST_ROW).action(Arguments.storeTrue()).help("first row contains column headers");
Argument argCsvColumns = groupDatasourceOptions.addArgument("--csv-columns").metavar("<list>").dest(Dest.CSV_COLUMNS).help("Comma separated list of column names");
groupDatasourceOptions.addArgument("--csv-record-del").metavar("<delimiter>").dest(Dest.CSV_RECORD_DEL).setDefault(System.getProperty("line.separator")).help("CSV Record Delimiter - defaults to line.separator");
groupDatasourceOptions.addArgument("--csv-field-del").metavar("<delimiter>").dest(Dest.CSV_FIELD_DEL).setDefault(",").help("CSV Field Delimiter - defaults to \",\"");
groupDatasourceOptions.addArgument("--csv-charset").metavar("<charset>").dest(Dest.CSV_CHARSET).setDefault("utf-8").help("CSV charset - defaults to \"utf-8\"");
Argument argXmlXpath = groupDatasourceOptions.addArgument("--xml-xpath").metavar("<xpath>").dest(Dest.XML_XPATH).help("XPath for XML Datasource");
Argument argJsonQuery = groupDatasourceOptions.addArgument("--json-query").metavar("<jsonquery>").dest(Dest.JSON_QUERY).help("JSON query string for JSON Datasource");
ArgumentGroup groupOutputOptions = parser.addArgumentGroup("output options");
groupOutputOptions.addArgument("-N").metavar("<printername>").dest(Dest.PRINTER_NAME).help("name of printer");
groupOutputOptions.addArgument("-d").dest(Dest.WITH_PRINT_DIALOG).action(Arguments.storeTrue()).help("show print dialog when printing");
groupOutputOptions.addArgument("-s").metavar("<reportname>").dest(Dest.REPORT_NAME).help("set internal report/document name when printing");
groupOutputOptions.addArgument("-c").metavar("<copies>").dest(Dest.COPIES)
.type(Integer.class).choices(Arguments.range(1, Integer.MAX_VALUE))
.help("number of copies. Defaults to 1");
groupOutputOptions.addArgument("--out-field-del").metavar("<delimiter>").dest(Dest.OUT_FIELD_DEL).setDefault(",").help("Export CSV (Metadata) Field Delimiter - defaults to \",\"");
groupOutputOptions.addArgument("--out-charset").metavar("<charset>").dest(Dest.OUT_CHARSET).setDefault("utf-8").help("Export CSV (Metadata) Charset - defaults to \"utf-8\"");
allArguments.put(argDbHost.getDest(), argDbHost);
allArguments.put(argDbUser.getDest(), argDbUser);
allArguments.put(argDbPasswd.getDest(), argDbPasswd);
allArguments.put(argDbName.getDest(), argDbName);
allArguments.put(argDbSid.getDest(), argDbSid);
allArguments.put(argDbPort.getDest(), argDbPort);
allArguments.put(argDbDriver.getDest(), argDbDriver);
allArguments.put(argDbUrl.getDest(), argDbUrl);
allArguments.put(argDataFile.getDest(), argDataFile);
allArguments.put(argCsvColumns.getDest(), argCsvColumns);
allArguments.put(argXmlXpath.getDest(), argXmlXpath);
allArguments.put(argJsonQuery.getDest(), argJsonQuery);
}
示例13: nonSolrCloud
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
private Argument nonSolrCloud(Argument arg) {
return showNonSolrCloud ? arg : arg.help(FeatureControl.SUPPRESS);
}
示例14: convert
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
@Override
public Path convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException {
Path file = new Path(value);
try {
fs = file.getFileSystem(conf);
if (verifyHasScheme && !isSystemIn(file)) {
verifyHasScheme(parser, file);
}
if (verifyScheme != null && !isSystemIn(file)) {
verifyScheme(parser, file);
}
if (verifyIsAbsolute && !isSystemIn(file)) {
verifyIsAbsolute(parser, file);
}
if (verifyExists && !isSystemIn(file)) {
verifyExists(parser, file);
}
if (verifyNotExists && !isSystemIn(file)) {
verifyNotExists(parser, file);
}
if (verifyIsFile && !isSystemIn(file)) {
verifyIsFile(parser, file);
}
if (verifyIsDirectory && !isSystemIn(file)) {
verifyIsDirectory(parser, file);
}
if (verifyCanRead && !isSystemIn(file)) {
verifyCanRead(parser, file);
}
if (verifyCanWrite && !isSystemIn(file)) {
verifyCanWrite(parser, file);
}
if (verifyCanWriteParent && !isSystemIn(file)) {
verifyCanWriteParent(parser, file);
}
if (verifyCanExecute && !isSystemIn(file)) {
verifyCanExecute(parser, file);
}
} catch (IOException e) {
throw new ArgumentParserException(e, parser);
}
return file;
}
示例15: convert
import net.sourceforge.argparse4j.inf.Argument; //导入依赖的package包/类
default T convert(final ArgumentParser var1, final Argument var2, final String input)
throws ArgumentParserException {
return convert(input);
}