public class Cli extends Object
Flag> accessors for the values. Arguments value must be
initialized before any flag values are accessed by Flag>.get() method. If arguments are provided as
String[] array, the array will be parsed by LongKeyValueParser class,
but any CLI parsing front-end can be used and arguments can be passed into Cli.init() method as
ImmutableMultimap.
Clients should be using exclusively static methods provided by this class as CLI arguments are expected to be
immutable during the application runtime. An second attempt to call Cli.init() will result in an
IllegalStateException. For integration testing of application modules, we provide Cli.setArguments()
and Cli.clear() methods.
Example:
{@code| Modifier and Type | Method and Description |
|---|---|
com.google.common.collect.ImmutableCollection<String> |
allArguments(FlagID flagID) |
static void |
clear()
Clears flag values after test case completes.
|
static <T> Flag<T> |
create(Class<T> type,
String name)
Returns flag value accessor, which can be used to retrieve the flag value supplied
by command line arguments.
|
TypeConversions |
getTypeConversions()
Type conversions used by Cli.
|
static void |
init(com.google.common.collect.ImmutableMultimap<String,String> args)
Initializes flag values from an
ImmutableMultimap. |
static void |
init(String[] args)
Initializes flag values from array of command-line arguments.
|
static void |
printUsage(String packagePrefix)
Prints user-readable usage help for all cli in a given package
|
String |
singleArgument(FlagID flagID) |
static Flag<String> |
string(String name)
Returns flag value accessor for
String type. |
public static void init(String[] args) throws IllegalStateException
args - Array of command-line arguments as passed to the main() methodIllegalStateExceptionpublic static void init(com.google.common.collect.ImmutableMultimap<String,String> args) throws IllegalStateException
ImmutableMultimap.args - Parsed command-line argumentsIllegalStateExceptionpublic static Flag<String> string(String name)
String type. See create().public static <T> Flag<T> create(Class<T> type, String name)
string(), ...)
should be used for readability reasons.
&at;Usage("Specifies path to input file")
private static final Flag<String> inputPathFlag = Cli.create(String.class, "inputPath");
T - is the same as flag value typetype - of the provided flag valuename - of the flag. This is must match the name the field or name attribute in @Usage annotationnamepublic static void printUsage(String packagePrefix)
public static void clear()
public TypeConversions getTypeConversions()
Copyright © 2016. All rights reserved.