Package io.github.qishr.cascara.common.util
Class RegexTransformer
java.lang.Object
io.github.qishr.cascara.common.util.CommandLine.RegexTransformer
All Implemented Interfaces:
INegatableOptionTransformer
Enclosing Class:
io.github.qishr.cascara.common.util.CommandLine
public static class RegexTransformer
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 createDefault by this class.
See the picocli.CommandLine.RegexTransformer.Builder for an example of customizing this to create negative forms for short options.
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
| public static | io.github.qishr.cascara.common.util.CommandLine.RegexTransformer.Builder | Builder for creating RegexTransformer objects. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
| public static RegexTransformer | createDefault() | Returns the RegexTransformer used by default for negatable options. |
| public static RegexTransformer | createCaseInsensitive() | Returns the RegexTransformer for case-insensitive negatable options. |
| public String | makeNegative(String optionName, CommandSpec cmd) | |
| public String | makeSynopsis(String optionName, CommandSpec cmd) | |
| public String | toString() |
Method Details
createDefault
public static RegexTransformer 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
createCaseInsensitive
public static RegexTransformer createCaseInsensitive()
Returns the RegexTransformer for case-insensitive negatable options.
The regular expressions for case-insensitive negatable options
Regex
Negative Replacement
Synopsis Replacement
Comment
^--((?i)no)-(\w(-|\w)*)$
--$2
--[$1-]$2
Converts --no-force to --force
and --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
public String makeNegative(String optionName, CommandSpec cmd)
Specified By:
makeSynopsis
public String makeSynopsis(String optionName, CommandSpec cmd)
Specified By:
toString
public String toString()