Package net.morimekta.console.args
Class BaseOption
- java.lang.Object
-
- net.morimekta.console.args.BaseArgument
-
- net.morimekta.console.args.BaseOption
-
public abstract class BaseOption extends BaseArgument
Argument definition base interface.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseOption(java.lang.String name, java.lang.String shortNames, java.lang.String metaVar, java.lang.String usage, java.lang.String defaultValue, boolean repeated, boolean required, boolean hidden)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
apply(ArgumentList args)
Parse the argument list, including the argument string that triggered the call.abstract int
applyShort(java.lang.String opts, ArgumentList args)
When handling a list of short options, except for the last short option.java.lang.String
getMetaVar()
Meta variable to show in usage printout.java.lang.String
getPrefix()
Prefix part of the usage usage message.java.lang.String
getShortNames()
Each character of the shortNames string is handled as a short option that is parsed with the -[short] style.java.lang.String
getSingleLineUsage()
Get the argument's single line usage string.protected java.lang.String
nameOrShort()
Handy getter mostly to be used in exception naming.-
Methods inherited from class net.morimekta.console.args.BaseArgument
getDefaultValue, getName, getUsage, isHidden, isRepeated, isRequired, validate
-
-
-
-
Method Detail
-
getShortNames
public java.lang.String getShortNames()
Each character of the shortNames string is handled as a short option that is parsed with the -[short] style. If the string is empty or null, no short options are provided.- Returns:
- The short names
-
getMetaVar
public java.lang.String getMetaVar()
Meta variable to show in usage printout.- Returns:
- The meta variable.
-
getSingleLineUsage
public java.lang.String getSingleLineUsage()
Description copied from class:BaseArgument
Get the argument's single line usage string.- Specified by:
getSingleLineUsage
in classBaseArgument
- Returns:
- The single-line usage string.
-
getPrefix
public java.lang.String getPrefix()
Description copied from class:BaseArgument
Prefix part of the usage usage message.- Specified by:
getPrefix
in classBaseArgument
- Returns:
- The usage prefix.
-
applyShort
public abstract int applyShort(java.lang.String opts, ArgumentList args)
When handling a list of short options, except for the last short option.- Parameters:
opts
- The remaining characters of the short opt list.args
- The list of arguments including the short opt list.- Returns:
- The number of arguments consumed. If 0 is returned, will handle as the short option char was the only thing being consumed.
-
apply
public abstract int apply(ArgumentList args)
Parse the argument list, including the argument string that triggered the call. And handle it's value or values.- Specified by:
apply
in classBaseArgument
- Parameters:
args
- The list of arguments.- Returns:
- The number of arguments consumed.
- Throws:
ArgumentException
- If the passed arguments are not valid.
-
nameOrShort
protected java.lang.String nameOrShort()
Handy getter mostly to be used in exception naming.- Returns:
- The argument's name or first short name.
-
-