Package com.sampullara.cli
Class Args
java.lang.Object
com.sampullara.cli.Args
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final List<Args.ValueCreator> static final Args.ValueCreatorstatic final intstatic final Args.ValueCreatorArgs.ValueCreatorbuilding object using a one arg constructor taking aStringobject as parameterprivate static List<Args.ValueCreator> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidprivate static voidaddPropertyArgument(Class type, PropertyDescriptor property, Object target, Object value, String delimiter) static Args.ValueCreatorbyStaticMethodInvocation(Class<?> compatibleType, String methodName) Creates aArgs.ValueCreatorobject able to create object assignable from given type, using a static one arg method which name is the the given one taking a String object as parameterprivate static ObjectconsumeArgumentValue(Class<?> type, Argument argument, Iterator<String> i) private static ObjectcreateValue(Class<?> type, String valueAsString) private static voidfieldUsage(PrintStream errStream, Object target, Field field) (package private) static StringgetEnumPossibleValues(Class<?> clazz) getEnumPossibleValuesImpl(Class<T> clazz) (package private) static StringgetName(Argument argument, PropertyDescriptor property) (package private) static StringgetPossibleValuesViaProvider(Class<? extends Callable<List<String>>> provider) private static StringgetTypeName(Class<?> type) private static Objectprivate static voidParse a set of arguments and populate the target with the appropriate values.parseOrExit(Object target, String[] args) A convenience method for parsing and automatically producing error messages.private static voidprocessField(Object target, Field field, List<String> arguments) private static voidprocessProperty(Object target, PropertyDescriptor property, List<String> arguments) private static voidpropertyUsage(PrintStream errStream, Object target, PropertyDescriptor field) private static voidpropertyUsage(PrintStream errStream, String prefix, String name, String alias, Class<?> type, String delimiter, String description, Object defaultValue, List<String> possibleValues) static voidAllows external extension of the valiue creators.static voidCleanup of registered ValueCreators (mainly for tests)(package private) static void(package private) static voidsetProperty(Class<?> type, PropertyDescriptor property, Object target, Object value, String delimiter) static voidusage(PrintStream errStream, Object target) Generate usage information based on the target annotations.static voidusage(PrintStream errStream, Object target, Class mainClass) Generate usage information based on the target annotations.static voidGenerate usage information based on the target annotations.
-
Field Details
-
EX_USAGE
public static final int EX_USAGE- See Also:
-
FROM_STRING_CONSTRUCTOR
Args.ValueCreatorbuilding object using a one arg constructor taking aStringobject as parameter -
ENUM_CREATOR
-
DEFAULT_VALUE_CREATORS
-
valueCreators
-
-
Constructor Details
-
Args
public Args()
-
-
Method Details
-
parseOrExit
A convenience method for parsing and automatically producing error messages.- Parameters:
target- Either an instance or a classargs- The arguments you want to parse and populate- Returns:
- The list of arguments that were not consumed
-
parse
-
parse
Parse a set of arguments and populate the target with the appropriate values.- Parameters:
target- Either an instance or a classargs- The arguments you want to parse and populatefailOnExtraFlags- Throw an IllegalArgumentException if extra flags are present- Returns:
- The list of arguments that were not consumed
-
processField
-
addArgument
-
addPropertyArgument
private static void addPropertyArgument(Class type, PropertyDescriptor property, Object target, Object value, String delimiter) -
processProperty
private static void processProperty(Object target, PropertyDescriptor property, List<String> arguments) -
usage
Generate usage information based on the target annotations.- Parameters:
target- An instance or class.
-
usage
Generate usage information based on the target annotations.- Parameters:
errStream- APrintStreamto print the usage information to.target- An instance or class.
-
usage
Generate usage information based on the target annotations.- Parameters:
errStream- APrintStreamto print the usage information to.target- An instance or class.mainClass- The class containing the main method
-
fieldUsage
-
propertyUsage
-
propertyUsage
-
getTypeName
-
getName
-
consumeArgumentValue
-
setProperty
static void setProperty(Class<?> type, PropertyDescriptor property, Object target, Object value, String delimiter) -
getAlias
-
getName
-
setField
-
getValue
private static Object getValue(Class<?> type, Object value, String delimiter) throws NoSuchMethodException - Throws:
NoSuchMethodException
-
createValue
- Throws:
NoSuchMethodException
-
makeAccessible
-
getPossibleValues
-
getPossibleValuesViaProvider
-
getEnumPossibleValues
-
getEnumPossibleValuesImpl
-
byStaticMethodInvocation
public static Args.ValueCreator byStaticMethodInvocation(Class<?> compatibleType, String methodName) Creates aArgs.ValueCreatorobject able to create object assignable from given type, using a static one arg method which name is the the given one taking a String object as parameter- Parameters:
compatibleType- the base assignable for which this object will try to invoke the given methodmethodName- the name of the one arg method taking a String as parameter that will be used to built a new value- Returns:
- null if the object could not be created, the value otherwise
-
registerValueCreator
Allows external extension of the valiue creators.- Parameters:
vc- another value creator to take into account for trying to create values
-
resetValueCreators
public static void resetValueCreators()Cleanup of registered ValueCreators (mainly for tests)
-