Package nz.org.riskscape.picocli
Class CommandLine.RegexTransformer
java.lang.Object
nz.org.riskscape.picocli.CommandLine.RegexTransformer
- All Implemented Interfaces:
CommandLine.INegatableOptionTransformer
- Enclosing class:
- CommandLine
public static class CommandLine.RegexTransformer
extends Object
implements CommandLine.INegatableOptionTransformer
A regular expression-based option name transformation for negatable options.
A common way to negate GNU *nix long options is to prefix them with "no-"
, so
for a --force
option the negative version would be --no-force
.
Java has the -XX:[+|-]
JVM options, where
"Boolean options are turned on with -XX:+<option>
and turned off with -XX:-<option>
".
These are the negative forms supported by default by this class.
See the picocli.CommandLine.RegexTransformer.Builder
for an example of customizing this to create negative forms for short options.
- Since:
- 4.0
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder for creatingRegexTransformer
objects. -
Method Summary
Modifier and TypeMethodDescriptionstatic CommandLine.RegexTransformer
Returns theRegexTransformer
used by default for negatable options.makeNegative
(String optionName, CommandLine.Model.CommandSpec cmd) Returns the negative form of the specified option name for the parser to recognize when parsing command line arguments.makeSynopsis
(String optionName, CommandLine.Model.CommandSpec cmd) Returns the documentation string to show in the synopsis and usage help message for the specified option.toString()
-
Method Details
-
createDefault
Returns the
RegexTransformer
used by default for negatable options.The regular expressions used by default for negatable options Regex Negative Replacement Synopsis Replacement Comment ^--no-(\w(-|\w))$ --$1 --[no-]$1 Converts --no-force
to--force
^--(\w(-|\w))$ --no-$1 --[no-]$1 Converts --force
to--no-force
^(-|--)(\w:)+(\w(-|\w))$ $1$2-$3 $1$2(+|-)$3 Converts -XX:+Inline
to-XX:-Inline
^(-|--)(\w:)-(\w(-|\w))$ $1$2+$3 $1$2(+|-)$3 Converts -XX:-Inline
to-XX:+Inline
-
makeNegative
Returns the negative form of the specified option name for the parser to recognize when parsing command line arguments.- Specified by:
makeNegative
in interfaceCommandLine.INegatableOptionTransformer
- Parameters:
optionName
- the option name to create a negative form for, for example--force
cmd
- the command that the option is part of- Returns:
- the negative form of the specified option name, for example
--no-force
-
makeSynopsis
Returns the documentation string to show in the synopsis and usage help message for the specified option. The returned value should be concise and clearly suggest that both the positive and the negative form are valid option names- Specified by:
makeSynopsis
in interfaceCommandLine.INegatableOptionTransformer
- Parameters:
optionName
- the option name to create a documentation string for, for example--force
, or-XX:+<option>
cmd
- the command that the option is part of- Returns:
- the documentation string for the negatable option, for example
--[no-]force
, or-XX:(+|-)<option>
-
toString
-