Skip to content

Commit

Permalink
[#259] small doc fixes for @Inject
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Jun 20, 2018
1 parent 21b6871 commit 34f51d2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ Usage: <main class>
Custom handlers can extend `AbstractHandler` to inherit this behaviour.

=== `@Inject` Annotation
Picocli 3.2 introduces a custom `@Inject` annotation (not `javax.inject.Inject`) for injecting the `CommandSpec` model of the command into a command field.
Picocli 3.2 introduces a custom `@Inject` annotation (`picocli.CommandLine.Inject`, not `javax.inject.Inject`) for injecting the `CommandSpec` model of the command into a command field.

This is useful when a command needs to use the picocli API, for example to walk the command hierarchy and iterate over its sibling commands.
This complements the `@ParentCommand` annotation; the `@ParentCommand` annotation injects a user-defined command object, whereas this annotation injects a picocli class.
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -2183,11 +2183,10 @@ private static class NoCompletionCandidates implements Iterable<String> {
String name() default "";
}
/**
* Fields annotated with {@code @Inject} will be initialized with the {@code CommandLine} or {@code CommandSpec} for the command the field is part of. Example usage:
* Fields annotated with {@code @Inject} will be initialized with the {@code CommandSpec} for the command the field is part of. Example usage:
* <pre>
* class InjectExample implements Runnable {
* &#064;Inject CommandLine commandLine; // usually you inject either the CommandLine
* &#064;Inject CommandSpec commandSpec; // or the CommandSpec
* &#064;Inject CommandSpec commandSpec;
* //...
* public void run() {
* // do something with the injected objects
Expand Down

0 comments on commit 34f51d2

Please sign in to comment.