Top Description Fields Constructors Methods
io.vertx.core.cli.impl

public Class DefaultParser

extends Object
Class Inheritance
Imports
io.vertx.core.cli.*, java.util.ArrayList, .Collections, .Iterator, .List, .Objects, java.util.stream.Collectors

The default implementation of the command line parser. Absolutely not thread safe!
Author
Clement Escoffier

Field Summary

Modifier and TypeField and Description
private CLI
private DefaultCommandLine
protected Option
protected List<Option>
private boolean
protected String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private void
private String

Returns:

the found prefix.
getLongPrefix
(String
the token
token
)

Search for a prefix that is the long name of an option (-Xmx512m)

public List<Option>

Returns:

the options matching the partial name specified, or an empty list if none matches
getMatchingOptions
(String
the partial name of the option
opt
)

Returns the options with a long name starting with the name specified.

public Option

Returns:

the option represented by opt
getOption
(String
short or long name of the Option
opt
)

Retrieve the Option matching the long or short name specified.

private List<Option>
private void
protected void
private void
handleLongOption(String
the command line token to handle
token
)

Handles the following tokens:

--L --L=V --L V --l

private void
handleLongOptionWithEqual(String
the command line token to handle
token
)

Handles the following tokens:

--L=V -L=V --l=V -l=V

private void
handleLongOptionWithoutEqual(String
the command line token to handle
token
)

Handles the following tokens:

--L -L --l -l

private void
private void
handleShortAndLongOption(String
the command line token to handle
token
)

Handles the following tokens:

-S -SV -S V -S=V

-L -LV -L V -L=V -l

private boolean
private boolean
private boolean
private boolean

Returns:

true if the token represents an option (long name match)
isLongOption
(String
the token
token
)

Tells if the token looks like a long option.

private boolean

Returns:

true if the token represents a negative number
isNegativeNumber
(String
the token
token
)

Check if the token is a negative number.

private boolean

Returns:

true if the token represents an option
isOption
(String
the token
token
)

Tells if the token looks like an option.

private boolean

Returns:

true if the token represents an option (short name match)
isShortOption
(String
the token
token
)

Tells if the token looks like a short option.

private boolean

Returns:

true if the token represents a value
isValue
(String
the token
token
)

Returns true is the token is a valid value.

public CommandLine
parse(CLI cli, List<String> cla)

public CommandLine
parse(CLI cli, List<String> cla, boolean validate)

pack-priv static String

Returns:

The string without the leading and trailing quotes.
stripLeadingAndTrailingQuotes
(String
The string from which the leading and trailing quotes should be removed.
str
)

Remove the leading and trailing quotes from str.

pack-priv static String

Returns:

the new String.
stripLeadingHyphens
(String
The string from which the hyphens should be removed.
str
)

Remove the hyphens from the beginning of str and return the new String.

private void
updateRequiredOptions(Option
the option
option
)

Removes the option from the list of expected elements.

protected void
private void
visit(String token)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cliback to summary
private CLI cli
commandLineback to summary
private DefaultCommandLine commandLine
currentback to summary
protected Option current
expectedOptsback to summary
protected List<Option> expectedOpts
skipParsingback to summary
private boolean skipParsing
tokenback to summary
protected String token

Constructor Detail

DefaultParserback to summary
public DefaultParser()

Method Detail

checkRequiredOptionsback to summary
private void checkRequiredOptions() throws MissingOptionException
checkRequiredValuesback to summary
private void checkRequiredValues() throws MissingValueException
getLongPrefixback to summary
private String getLongPrefix(String token)

Search for a prefix that is the long name of an option (-Xmx512m)

Parameters
token:String

the token

Returns:String

the found prefix.

getMatchingOptionsback to summary
public List<Option> getMatchingOptions(String opt)

Returns the options with a long name starting with the name specified.

Parameters
opt:String

the partial name of the option

Returns:List<Option>

the options matching the partial name specified, or an empty list if none matches

getOptionback to summary
public Option getOption(String opt)

Retrieve the Option matching the long or short name specified. The leading hyphens in the name are ignored (up to 2).

Parameters
opt:String

short or long name of the Option

Returns:Option

the option represented by opt

getRequiredOptionsback to summary
private List<Option> getRequiredOptions()
handleArgumentback to summary
private void handleArgument(String token)
handleConcatenatedOptionsback to summary
protected void handleConcatenatedOptions(String token) throws CLIException
handleLongOptionback to summary
private void handleLongOption(String token) throws CLIException

Handles the following tokens:

--L --L=V --L V --l

Parameters
token:String

the command line token to handle

handleLongOptionWithEqualback to summary
private void handleLongOptionWithEqual(String token) throws CLIException

Handles the following tokens:

--L=V -L=V --l=V -l=V

Parameters
token:String

the command line token to handle

handleLongOptionWithoutEqualback to summary
private void handleLongOptionWithoutEqual(String token) throws CLIException

Handles the following tokens:

--L -L --l -l

Parameters
token:String

the command line token to handle

handleOptionback to summary
private void handleOption(Option option) throws CLIException
handleShortAndLongOptionback to summary
private void handleShortAndLongOption(String token) throws CLIException

Handles the following tokens:

-S -SV -S V -S=V

-L -LV -L V -L=V -l

Parameters
token:String

the command line token to handle

hasOptionWithLongNameback to summary
private boolean hasOptionWithLongName(String name)
hasOptionWithShortNameback to summary
private boolean hasOptionWithShortName(String name)
isAValidShortOptionback to summary
private boolean isAValidShortOption(String token)
isLongOptionback to summary
private boolean isLongOption(String token)

Tells if the token looks like a long option.

Parameters
token:String

the token

Returns:boolean

true if the token represents an option (long name match)

isNegativeNumberback to summary
private boolean isNegativeNumber(String token)

Check if the token is a negative number.

Parameters
token:String

the token

Returns:boolean

true if the token represents a negative number

Annotations
@SuppressWarnings:ResultOfMethodCallIgnored
isOptionback to summary
private boolean isOption(String token)

Tells if the token looks like an option.

Parameters
token:String

the token

Returns:boolean

true if the token represents an option

isShortOptionback to summary
private boolean isShortOption(String token)

Tells if the token looks like a short option.

Parameters
token:String

the token

Returns:boolean

true if the token represents an option (short name match)

isValueback to summary
private boolean isValue(String token)

Returns true is the token is a valid value.

Parameters
token:String

the token

Returns:boolean

true if the token represents a value

parseback to summary
public CommandLine parse(CLI cli, List<String> cla) throws CLIException
parseback to summary
public CommandLine parse(CLI cli, List<String> cla, boolean validate) throws CLIException
stripLeadingAndTrailingQuotesback to summary
pack-priv static String stripLeadingAndTrailingQuotes(String str)

Remove the leading and trailing quotes from str. E.g. if str is '"one two"', then 'one two' is returned.

Parameters
str:String

The string from which the leading and trailing quotes should be removed.

Returns:String

The string without the leading and trailing quotes.

stripLeadingHyphensback to summary
pack-priv static String stripLeadingHyphens(String str)

Remove the hyphens from the beginning of str and return the new String.

Parameters
str:String

The string from which the hyphens should be removed.

Returns:String

the new String.

updateRequiredOptionsback to summary
private void updateRequiredOptions(Option option)

Removes the option from the list of expected elements.

Parameters
option:Option

the option

validateback to summary
protected void validate() throws CLIException
visitback to summary
private void visit(String token) throws CLIException