Package net.morimekta.console.args
Class Option
- java.lang.Object
-
- net.morimekta.console.args.BaseArgument
-
- net.morimekta.console.args.BaseOption
-
- net.morimekta.console.args.Option
-
public class Option extends BaseOption
Named option that for each invocation takes a single argument value, either the next argument, or from the same argument after a '=' delimiter.
-
-
Constructor Summary
Constructors Constructor Description Option(java.lang.String name, java.lang.String shortNames, java.lang.String metaVar, java.lang.String usage, java.util.function.Consumer<java.lang.String> setter)
Option(java.lang.String name, java.lang.String shortNames, java.lang.String metaVar, java.lang.String usage, java.util.function.Consumer<java.lang.String> setter, java.lang.String defaultValue)
Option(java.lang.String name, java.lang.String shortNames, java.lang.String metaVar, java.lang.String usage, java.util.function.Consumer<java.lang.String> setter, java.lang.String defaultValue, boolean repeated, boolean required, boolean hidden)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
apply(ArgumentList args)
Parse the argument list, including the argument string that triggered the call.int
applyShort(java.lang.String opts, ArgumentList args)
When handling a list of short options, except for the last short option.void
validate()
Called on all the arguments after the parsing is done to validate if all requirements have been passed.-
Methods inherited from class net.morimekta.console.args.BaseArgument
getDefaultValue, getName, getUsage, isHidden, isRepeated, isRequired
-
Methods inherited from class net.morimekta.console.args.BaseOption
getMetaVar, getPrefix, getShortNames, getSingleLineUsage, nameOrShort
-
-
-
-
Constructor Detail
-
Option
public Option(java.lang.String name, java.lang.String shortNames, java.lang.String metaVar, java.lang.String usage, java.util.function.Consumer<java.lang.String> setter)
-
Option
public Option(java.lang.String name, java.lang.String shortNames, java.lang.String metaVar, java.lang.String usage, java.util.function.Consumer<java.lang.String> setter, java.lang.String defaultValue)
-
Option
public Option(java.lang.String name, java.lang.String shortNames, java.lang.String metaVar, java.lang.String usage, java.util.function.Consumer<java.lang.String> setter, java.lang.String defaultValue, boolean repeated, boolean required, boolean hidden)
-
-
Method Detail
-
applyShort
public int applyShort(java.lang.String opts, ArgumentList args)
Description copied from class:BaseOption
When handling a list of short options, except for the last short option.- Specified by:
applyShort
in classBaseOption
- 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.
-
validate
public void validate() throws ArgumentException
Description copied from class:BaseArgument
Called on all the arguments after the parsing is done to validate if all requirements have been passed. Should throw anArgumentException
if is did not validate with the appropriate error message.- Specified by:
validate
in classBaseArgument
- Throws:
ArgumentException
-
apply
public int apply(ArgumentList args) throws ArgumentException
Description copied from class:BaseOption
Parse the argument list, including the argument string that triggered the call. And handle it's value or values.- Specified by:
apply
in classBaseOption
- Parameters:
args
- The list of arguments.- Returns:
- The number of arguments consumed.
- Throws:
ArgumentException
- If the passed arguments are not valid.
-
-