Skip to content

Commit

Permalink
Revert "[remkop#1428] DOC: make a note about subcommands with the sam…
Browse files Browse the repository at this point in the history
…e name as a default value"

This reverts commit 1449834.
  • Loading branch information
MarkoMackic committed Oct 17, 2021
1 parent 8ed2e70 commit f6f8d93
Showing 1 changed file with 0 additions and 25 deletions.
25 changes: 0 additions & 25 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8595,31 +8595,6 @@ class Git : Runnable {
By default, the synopsis of a command with subcommands shows a trailing `[COMMAND]`, indicating that a subcommand can optionally be specified.
To show that the subcommand is mandatory, use the `synopsisSubcommandLabel` attribute to replace this string with `COMMAND` (without the `[` and `]` brackets).

=== Subcommands and default values

There are some scenarios where picocli can not parse an option with a default value which is the same as a subcommand name. To work around this, you can parse the option yourself using <<Custom Parameter Processing,`IParameterConsumer`>>. A simple implementation is shown below. See https://github.com/remkop/picocli/issues/1428[this issue] for more details.


.Kotlin
[source,kotlin,role="secondary"]
----
class MyParameterConsumer : CommandLine.IParameterConsumer {
override fun consumeParameters(
args: Stack<String>,
argSpec: CommandLine.Model.ArgSpec,
commandSpec: CommandLine.Model.CommandSpec
) {
if (args.isEmpty()) {
throw CommandLine.ParameterException(
commandSpec.commandLine(),
"Missing required parameter for option " +
(argSpec as CommandLine.Model.OptionSpec).longestName()
)
}
argSpec.setValue(args.pop());
}
}
----

== Reuse
You may find yourself defining the same options, parameters or command attributes in many command line applications.
Expand Down

0 comments on commit f6f8d93

Please sign in to comment.