@Option(names = "--no-backup", negatable = true,
+@Option(names = "--backup", negatable = true,
+ defaultValue = "true", fallbackValue = "true",
description = "Make a backup. True by default.")
-boolean backup = true;
+boolean backup;
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 1795128ff..344bfcf1f 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -25,6 +25,9 @@ Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96). * [#1878][#1876] Bugfix: Annotation processor now avoids loading resource bundles at compile time. Thanks to [Ruud Senden](https://github.com/rsenden) for the discussion and the pull request. * [#1881] DOC: Many documentation improvements. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request. * [#1855][#1857] DOC: Add new user manual section called [Rare Use Cases](https://picocli.info/#_rare_use_cases) detailing `System.exit` usage. Thanks to [Tadaya Tsuyukubo](https://github.com/ttddyy) for the pull request. +* [#1880] DOC: Improve documentation for negatable options that are true by default. Thanks to [Sebastian Hoß](https://github.com/sebhoss) for raising this. + + ## Deprecations No features were deprecated in this release. diff --git a/docs/index.adoc b/docs/index.adoc index 64db27581..f0c663ac8 100644 --- a/docs/index.adoc +++ b/docs/index.adoc @@ -843,27 +843,54 @@ If the negated form of the option is found, for example `--no-verbose`, the valu [TIP] .Negatable options that are `true` by default ==== -When a negatable option is `true` by default, give it the negative name. For example: +When a negatable option is `true` by default, give it both a `defaultValue` and a `fallbackValue` of `"true"`. For example: .Java [source,java,role="primary"] ---- -@Option(names = "--no-backup", negatable = true, +@Option(names = "--backup", negatable = true, + defaultValue = "true", fallbackValue = "true", description = "Make a backup. True by default.") -boolean backup = true; +boolean backup; ---- .Kotlin [source,kotlin,role="secondary"] ---- -@Option(names = ["--no-backup"], negatable = true, +@Option(names = ["--backup"], negatable = true, + defaultValue = "true", fallbackValue = "true", description = ["Make a backup. True by default."]) var backup = true ---- -When end users specify `--no-backup` on the command line, the value is set to `false`. +The table below shows the value assigned to the annotated option field for a number of possible user input strings: + +//.Negatable option values for various user input strings +//[grid=cols,cols="10,10",options="header"] +//|=== +//| End user input | Option value +//| (no args) | `true` +//| `--backup` | `true` +//| `--backup=true` | `true` +//| `--backup=false` | `false` +//| `--no-backup` | `false` +//| `--no-backup=true` | `false` +//| `--no-backup=false` | `true` +//|=== +// + +---- +End user input Option value +-------------- ------------ +(no args) true +--backup true +--backup=true true +--backup=false false +--no-backup false +--no-backup=true false +--no-backup=false true +---- -The negated form of this option is `--backup`, and if that is specified, the default value is applied. ==== === Positional Parameters diff --git a/docs/index.html b/docs/index.html index 39d0083d8..cfc704f11 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3214,29 +3214,41 @@
true
by defaultWhen a negatable option is true
by default, give it the negative name. For example:
When a negatable option is true
by default, give it both a defaultValue
and a fallbackValue
of "true"
. For example:
@Option(names = "--no-backup", negatable = true,
+@Option(names = "--backup", negatable = true,
+ defaultValue = "true", fallbackValue = "true",
description = "Make a backup. True by default.")
-boolean backup = true;
+boolean backup;
@Option(names = ["--no-backup"], negatable = true,
+@Option(names = ["--backup"], negatable = true,
+ defaultValue = "true", fallbackValue = "true",
description = ["Make a backup. True by default."])
var backup = true
When end users specify --no-backup
on the command line, the value is set to false
.
The table below shows the value assigned to the annotated option field for a number of possible user input strings:
+End user input Option value +-------------- ------------ +(no args) true +--backup true +--backup=true true +--backup=false false +--no-backup false +--no-backup=true false +--no-backup=false true
The negated form of this option is --backup
, and if that is specified, the default value is applied.