You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: RELEASE-NOTES.md
+30-2Lines changed: 30 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,9 @@ This release contains new features, bug fixes and other enhancements.
8
8
9
9
## Community Contributions
10
10
11
-
* [Andreas Deininger](https://github.com/deining) has been contributing to the documentation and other areas for a while, but recently went into overdrive :-) and contributed many, many new pull requests to improve the documentation. The user manual and Quick Guide now have a "foldable" table of contents, and examples in tabs, with many additional examples in Kotlin, Scala and Groovy. A lot of work went into this! Many thanks, Andreas!
12
-
* [Sualeh Fatehi](https://github.com/sualeh) contributed a pull request to `picocli-shell-jline3` that adds a built-in `clear` command and improves the `help` command.
11
+
* [Andreas Deininger](https://github.com/deining) has been contributing to the documentation and other areas for a long time, but recently went into overdrive :-) and contributed many, many new pull requests to improve the documentation. The user manual and Quick Guide now have a "foldable" table of contents, and examples in tabs, with many additional examples in Kotlin, Scala and Groovy. A lot of work went into this! Many thanks, Andreas!
12
+
* [Marko Mackic](https://github.com/MarkoMackic) contributed a pull request to add `IModelTransformer` API for user-defined model transformations after initialization and before parsing.
13
+
* [Sualeh Fatehi](https://github.com/sualeh) contributed a pull request to the `picocli-shell-jline3` module that adds a built-in `clear` command and improves the `help` command.
13
14
* [Daniel Gray](https://github.com/danielthegray) contributed a bug fix to prevent incorrectly defaulting inherited positional params after a subcommand.
14
15
* [nveeser-google](https://github.com/nveeser-google) contributed a fix for compiler warnings about `Annotation::getClass` and assignment in `if` condition.
15
16
* [Petr Hála](https://github.com/pehala) contributed a pull request to add a section on Mocking to user manual.
@@ -251,11 +253,37 @@ Attributes that are _not_ copied include:
251
253
* subcommands
252
254
* argument groups
253
255
256
+
### <a name="4.6.0-model-transformations"></a> Model Transformations
257
+
From picocli 4.6, it is possible to use the annotations API to modify the model (commands, options, subcommands, etc.) dynamically at runtime.
258
+
The `@Command` annotation now has a `modelTransformer` attribute where applications can specify a class that implements the `IModelTransformer` interface:
259
+
260
+
This allows applications to dynamically add or remove options, positional parameters or subcommands, or modify the command in any other way, based on some runtime condition.
private static class SubCmdFilter implements IModelTransformer {
267
+
public CommandSpec transform(CommandSpec commandSpec) {
268
+
if (Boolean.getBoolean("disable_sub")) {
269
+
commandSpec.removeSubcommand("sub");
270
+
}
271
+
return commandSpec;
272
+
}
273
+
}
274
+
275
+
@Command
276
+
private void sub() {
277
+
// subcommand business logic
278
+
}
279
+
}
280
+
```
254
281
255
282
## <a name="4.6.0-fixes"></a> Fixed issues
256
283
* [#1164] API: Add support for `@Command(scope=INHERIT)`. Thanks to [Nick Cross](https://github.com/rnc) for raising this.
257
284
* [#1191] API: Add `@PicocliScript2` annotation to support subcommand methods in Groovy scripts. Thanks to [Mattias Andersson](https://github.com/attiand) for raising this.
258
285
* [#1241] API: Add `mapFallbackValue` attribute to `@Options` and `@Parameters` annotations, and corresponding `ArgSpec.mapFallbackValue()`.
286
+
* [#1259][#1266] API: Add `IModelTransformer` to support user-defined model transformations after initialization and before parsing. Thanks to [Marko Mackic](https://github.com/MarkoMackic) for the pull request.
259
287
* [#1184] API: Added public methods `Help.Layout::colorScheme`, `Help.Layout::textTable`, `Help.Layout::optionRenderer`, `Help.Layout::parameterRenderer`, and `Help::calcLongOptionColumnWidth`.
260
288
* [#1254] API: Added `ArgSpec::root`: this method returns the original `ArgSpec` for inherited `ArgSpec` objects, and `null` for other `ArgSpec` objects. Thanks to [Daniel Gray](https://github.com/danielthegray) for the pull request.
261
289
* [#1256] API: Added `CommandSpec::removeSubcommand` method. Thanks to [Marko Mackic](https://github.com/MarkoMackic) for raising this.
Copy file name to clipboardExpand all lines: docs/index.adoc
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9894,6 +9894,53 @@ override fun <K : Any> create(clazz: Class<K>): K {
9894
9894
}
9895
9895
----
9896
9896
9897
+
=== Model Transformations
9898
+
From picocli 4.6, it is possible to use the annotations API to modify the model (commands, options, subcommands, etc.) dynamically at runtime.
9899
+
The `@Command` annotation now has a `modelTransformer` attribute where applications can specify a class that implements the `IModelTransformer` interface:
9900
+
9901
+
[source,java]
9902
+
----
9903
+
interface IModelTransformer {
9904
+
/**
9905
+
* Given an original CommandSpec, return the object that should be used
9906
+
* instead. Implementors may modify the specified CommandSpec and return it,
9907
+
* or create a full or partial copy of the specified CommandSpec, and return
9908
+
* that, or even return a completely new CommandSpec.
9909
+
* <p>
9910
+
* Implementors are free to add or remove options, positional parameters,
9911
+
* subcommands or modify the command in any other way.
9912
+
* </p><p>
9913
+
* This method is called once, after the full command hierarchy is
9914
+
* constructed, and before any command line arguments are parsed.
9915
+
* </p>
9916
+
* @return the CommandSpec to use instead of the specified one
9917
+
*/
9918
+
CommandSpec transform(CommandSpec commandSpec);
9919
+
}
9920
+
----
9921
+
9922
+
This allows applications to dynamically add or remove options, positional parameters or subcommands, or modify the command in any other way, based on some runtime condition.
0 commit comments