CommandLine.RegexTransformer (picocli 4.6.3 API)

picocli

## Class CommandLine.RegexTransformer

- java.lang.Object
- - 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 `CommandLine.RegexTransformer.Builder` for an example of customizing this to create negative forms for short options.

  Since:
    4.0

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `CommandLine.RegexTransformer.Builder` Builder for creating `RegexTransformer` objects.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static CommandLine.RegexTransformer` | `createCaseInsensitive()` Returns the `RegexTransformer` for case-insensitive negatable options.
    `static CommandLine.RegexTransformer` | `createDefault()` Returns the `RegexTransformer` used by default for negatable options.
    `String` | `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.
    `String` | `makeSynopsis(String optionName, CommandLine.Model.CommandSpec cmd)` Returns the documentation string to show in the synopsis and usage help message for the specified option.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### createDefault

          public static CommandLine.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 CommandLine.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,
                                     CommandLine.Model.CommandSpec cmd)

      Returns the negative form of the specified option name for the parser to recognize when parsing command line arguments.
      Specified by:
        `makeNegative` in interface `CommandLine.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

          public String makeSynopsis(String optionName,
                                     CommandLine.Model.CommandSpec cmd)

      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 interface `CommandLine.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

          public String toString()

      Overrides:
        `toString` in class `Object`