Skip to content

Commit

Permalink
[#455] command methods related
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Aug 29, 2018
1 parent 0c6b7d8 commit c5f3acc
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class SqlTypeConverter implements ITypeConverter<Integer> {
}
----

This may also be useful for applications that need a custom type converter but want to use the static convenience methods (`populateCommand`, `run`, `call`). The `converter` annotation does not require a `CommandLine` instance so it can be used with the static convenience methods.
This may also be useful for applications that need a custom type converter but want to use the static convenience methods (`populateCommand`, `run`, `call`, `invoke`). The `converter` annotation does not require a `CommandLine` instance so it can be used with the static convenience methods.

Type converters declared with the `converter` attribute need to have a public no-argument constructor to be instantiated, unless a <<Custom Factory>> is installed to instantiate classes.

Expand Down Expand Up @@ -619,7 +619,7 @@ For annotated fields, it is simplest to declare the field with a value:
@Option(names = "-c", description = "The count (default: ${DEFAULT-VALUE})")
int count = 123; // default value is 123
----
For <<option-parameters-methods,annotated methods>>, use the `defaultValue` annotation attribute. For example, for an annotated interface:
For <<option-parameters-methods,`@Option` and `@Parameters`-annotated methods>> and <<command-methods,`@Command`-annotated methods>>, use the `defaultValue` annotation attribute. For example, for an annotated interface:
[source,java]
----
interface Spec {
Expand All @@ -639,6 +639,16 @@ class Impl {
}
}
----
And finally for a command method:
[source,java]
----
class CommandMethod {
@Command(description = "Do something.")
void doit(@Option(names = "-c", defaultValue = "123") int count) {
// ...
}
}
----

Note that you can use the `${DEFAULT-VALUE}` variable in the `description` of the option or positional parameter and picocli will <<Show Default Values,show>> the actual default value.

Expand Down Expand Up @@ -1124,6 +1134,7 @@ The following <<Less Boilerplate,convenience methods>> automatically print help:

* `CommandLine::call`
* `CommandLine::run`
* `CommandLine::invoke`
* `CommandLine::parseWithHandler` (with the built-in `Run...` handlers)
* `CommandLine::parseWithHandlers` (with the built-in `Run...` handlers)

Expand Down Expand Up @@ -2040,7 +2051,8 @@ The most commonly used git commands are:
The above usage help message is produced from the annotations on the class below:
[source,java]
----
@Command(name = "git", mixinStandardHelpOptions = true, version = "subcommand demo - picocli 3.0",
@Command(name = "git", mixinStandardHelpOptions = true,
version = "subcommand demo - picocli 3.0",
subcommands = HelpCommand.class,
description = "Git is a fast, scalable, distributed revision control " +
"system with an unusually rich command set that provides both " +
Expand Down Expand Up @@ -2519,7 +2531,7 @@ Picocli provides some default `IParseResultHandler2` implementations for common


=== Stdout or Stderr
From picocli v3.0, the `run` and `call` convenience methods follow unix conventions:
From picocli v3.0, the `run`, `call` and `invoke` convenience methods follow unix conventions:
print to stdout when the user requested help, and print to stderr when the input was invalid or an unexpected error occurred.

Custom handlers can extend `AbstractHandler` to facilitate following this convention.
Expand Down

0 comments on commit c5f3acc

Please sign in to comment.