Package com.codingchili.core.context
Class CommandParser
java.lang.Object
com.codingchili.core.context.CommandParser
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addProperty(String key, String value)
Programmatically adds a property to the parsed command line.getAllValues(String name)
boolean
hasProperty(String name)
boolean
void
Parses the given command line and discards any prior state.
-
Constructor Details
-
CommandParser
- Parameters:
commandline
- a list starting with the command followed by properties. example: adduser --name foo --admin
-
-
Method Details
-
setPrefix
- Parameters:
prefix
- a prefix that prepends the command, removed when parsed. defaults to COMMAND_PREFIX inCoreStrings.COMMAND_PREFIX
- Returns:
- fluent
-
parse
Parses the given command line and discards any prior state.- Parameters:
line
- a commandline with properties.
-
getCommand
- Returns:
- the name of the command that was passed in the commandline.
-
addProperty
Programmatically adds a property to the parsed command line.- Parameters:
key
- the key of the property, example '--name'value
- the value of the property, prefixed with the key.
-
hasProperty
- Parameters:
name
- checks if the parsed commandline specifies the given property- Returns:
- true if the command contains the property
-
getValue
- Parameters:
name
- retrieves the property value by its name, excluding the prefix.- Returns:
- a property value if given, if multiple given then the first is returned.
-
isMulti
- Parameters:
name
- the name of the property to check if it has multiple values.- Returns:
- true if the given property has multiple values.
-
getAllValues
- Parameters:
name
- retrieves all property values for the given property name, excluding the prefix.- Returns:
- all property values for the given property name.
-