public class Args extends Object
A key is defined with one or more dashes in the beginning, for example:
'-path' '--path'A key/value pair can be either one single String from the array where there's a '=' delimiter between the key and value, like so:
'--path=/my/path/to/something'...or consist of two (consecutive) strings from the array, like so:
'-path' '/my/path/to/something'Multiple values for an option is supported, however the only means of extracting all values is be using
interpretOptions(String, Function, Function, Validator...)
, all other methods revolve
around single value, i.e. will fail if there are multiple.
Options can have metadata which can be extracted using
interpretOptions(String, Function, Function, Validator...)
. Metadata looks like:
--my-option:Metadata my-valuewhere
Metadata
would be the metadata of my-value
.Modifier and Type | Class and Description |
---|---|
static class |
Args.ArgsParser |
static class |
Args.Option<T> |
Constructor and Description |
---|
Args(org.neo4j.function.Function<String,Args.Option<String>> optionParser,
Map<String,String> source) |
Args(Map<String,String> source) |
Modifier and Type | Method and Description |
---|---|
String[] |
asArgs() |
Map<String,String> |
asMap() |
String |
get(String key) |
String |
get(String key,
String defaultValue) |
String |
get(String key,
String defaultValueIfNotFound,
String defaultValueIfNoValue) |
boolean |
getBoolean(String key)
Like calling
getBoolean(String, Boolean) with false for default value. |
Boolean |
getBoolean(String key,
Boolean defaultValueIfNotSpecified)
|
Boolean |
getBoolean(String key,
Boolean defaultValueIfNotSpecified,
Boolean defaultValueIfSpecifiedButNoValue)
Parses a
boolean argument. |
long |
getDuration(String key,
long defaultValueInMillis) |
<T extends Enum<T>> |
getEnum(Class<T> enumClass,
String key,
T defaultValue) |
Number |
getNumber(String key,
Number defaultValue) |
boolean |
has(String key) |
boolean |
hasNonNull(String key) |
<T> T |
interpretOption(String key,
org.neo4j.function.Function<String,T> defaultValue,
org.neo4j.function.Function<String,T> converter,
org.neo4j.kernel.impl.util.Validator<T>... validators) |
<T> Collection<T> |
interpretOptions(String key,
org.neo4j.function.Function<String,T> defaultValue,
org.neo4j.function.Function<String,T> converter,
org.neo4j.kernel.impl.util.Validator<T>... validators)
An option can be specified multiple times; this method will allow interpreting all values for
the given key, returning a
Collection . |
<T> Collection<Args.Option<T>> |
interpretOptionsWithMetadata(String key,
org.neo4j.function.Function<String,T> defaultValue,
org.neo4j.function.Function<String,T> converter,
org.neo4j.kernel.impl.util.Validator<T>... validators)
An option can be specified multiple times; this method will allow interpreting all values for
the given key, returning a
Collection . |
<T> T |
interpretOrphan(int index,
org.neo4j.function.Function<String,T> defaultValue,
org.neo4j.function.Function<String,T> converter,
org.neo4j.kernel.impl.util.Validator<T>... validators) |
static String |
jarUsage(Class<?> main,
String... params) |
List<String> |
orphans() |
String[] |
orphansAsArray() |
static Args |
parse(String... args) |
String[] |
source() |
static String[] |
splitLongLine(String description,
int maxLength)
Useful for printing usage where the description itself shouldn't have knowledge about the width
of the window where it's printed.
|
String |
toString() |
static Args.ArgsParser |
withFlags(String... flags) |
public static Args.ArgsParser withFlags(String... flags)
public String[] source()
public boolean has(String key)
public boolean hasNonNull(String key)
public long getDuration(String key, long defaultValueInMillis)
public boolean getBoolean(String key)
getBoolean(String, Boolean)
with false
for default value.
This is the most common case, i.e. returns true
if boolean argument was specified as:
false.
key
- argument key.true
if argument was specified w/o value, or w/ value true
, otherwise false
.public Boolean getBoolean(String key, Boolean defaultValueIfNotSpecified)
getBoolean(String, Boolean, Boolean)
with true
for
defaultValueIfNoValue
, i.e. specifying --myarg
will interpret it as true
.public Boolean getBoolean(String key, Boolean defaultValueIfNotSpecified, Boolean defaultValueIfSpecifiedButNoValue)
boolean
argument. There are a couple of cases:
defaultValueIfNotSpecified
will be returned.--myboolean. In this case the value of
defaultValueIfNotSpecified
will be returned.--myboolean=true. In this case the actual value will be returned.
key
- argument key.defaultValueIfNotSpecified
- used if argument not specified.defaultValueIfSpecifiedButNoValue
- used if argument specified w/o value.public String[] orphansAsArray()
public String[] asArgs()
public static String[] splitLongLine(String description, int maxLength)
description
- text to split, if needed.maxLength
- line length to split at, actually closest previous white space.@SafeVarargs public final <T> T interpretOption(String key, org.neo4j.function.Function<String,T> defaultValue, org.neo4j.function.Function<String,T> converter, org.neo4j.kernel.impl.util.Validator<T>... validators)
@SafeVarargs public final <T> Collection<T> interpretOptions(String key, org.neo4j.function.Function<String,T> defaultValue, org.neo4j.function.Function<String,T> converter, org.neo4j.kernel.impl.util.Validator<T>... validators)
Collection
. This is the only means of extracting multiple values
for any given option. All other methods revolve around zero or one value for an option.T
- The type of the option valueskey
- Key of the optiondefaultValue
- Default value value of the optionconverter
- Converter to usevalidators
- Validators to use@SafeVarargs public final <T> Collection<Args.Option<T>> interpretOptionsWithMetadata(String key, org.neo4j.function.Function<String,T> defaultValue, org.neo4j.function.Function<String,T> converter, org.neo4j.kernel.impl.util.Validator<T>... validators)
Collection
. This is the only means of extracting multiple values
for any given option. All other methods revolve around zero or one value for an option.
This is also the only means of extracting metadata about a options. Metadata can be supplied as part
of the option key, like --my-option:Metadata "my value".T
- The type of the option valueskey
- Key of the optiondefaultValue
- Default value value of the optionconverter
- Converter to usevalidators
- Validators to use@SafeVarargs public final <T> T interpretOrphan(int index, org.neo4j.function.Function<String,T> defaultValue, org.neo4j.function.Function<String,T> converter, org.neo4j.kernel.impl.util.Validator<T>... validators)
Copyright © 2002–2015 The Neo4j Graph Database Project. All rights reserved.