pax_global_header00006660000000000000000000000064134576420300014516gustar00rootroot0000000000000052 comment=a7443993152cf042525687c7085a63d167991f90 picocli-3.9.6/000077500000000000000000000000001345764203000131575ustar00rootroot00000000000000picocli-3.9.6/.gitattributes000066400000000000000000000016471345764203000160620ustar00rootroot00000000000000# Handle line endings automatically for files detected as text # and leave all files detected as binary untouched. * text=auto # # The above will handle all files NOT found below # # These files are text and should be normalized (Convert crlf => lf) *.adoc text *.css text *.gradle text *.groovy text *.html text *.java text *.js text *.md text *.properties text *.txt text *.yml text # These files are text and must be normalized to lf gradlew text eol=lf *.sh text eol=lf *.bash text eol=lf # These files are text and must be normalized to crlf *.bat text eol=crlf # These files are binary and should be left untouched # (binary is a macro for -text -diff) *.gif binary *.ico binary *.jar binary *.jpg binary *.jpeg binary *.png binary picocli-3.9.6/.gitignore000066400000000000000000000001011345764203000151370ustar00rootroot00000000000000.gradle/ .idea/ build/ local.properties target/ tmp/ picocli.iml picocli-3.9.6/.travis.yml000066400000000000000000000022021345764203000152640ustar00rootroot00000000000000env: global: # for CodeClimate - CC_TEST_REPORTER_ID=83a2e05f875e3a67f60a1969f20a558a3de03a7592052c8bf52807d0e317f01a language: java jdk: - oraclejdk8 - oraclejdk11 - oraclejdk-ea - openjdk8 - openjdk9 - openjdk10 - openjdk11 - openjdk-ea # - openjdk7 # Disabled to avoid error java.security.NoSuchProviderException: no such provider: SunEC... # - oraclejdk7 # $ jdk_switcher use oraclejdk7 # Switching to Oracle JDK7 (java-7-oracle), JAVA_HOME will be set to /usr/lib/jvm/java-7-oracle # update-java-alternatives: directory does not exist: /usr/lib/jvm/java-7-oracle # ... # ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-7-oracle # # - openjdk6 # gradle 3.1 requires java 7 matrix: allow_failures: - jdk: oraclejdk-ea before_script: - chmod +x gradlew # for CodeClimate - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build script: - ./gradlew check --info after_success: - bash <(curl -s https://codecov.io/bash) - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT picocli-3.9.6/LICENSE000066400000000000000000000261351345764203000141730ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. picocli-3.9.6/README.md000066400000000000000000000335731345764203000144510ustar00rootroot00000000000000

picocli

[![GitHub Release](https://img.shields.io/github/release/remkop/picocli.svg)](https://github.com/remkop/picocli/releases) [![Build Status](https://travis-ci.org/remkop/picocli.svg?branch=master)](https://travis-ci.org/remkop/picocli) [![codecov](https://codecov.io/gh/remkop/picocli/branch/master/graph/badge.svg)](https://codecov.io/gh/remkop/picocli) [![Follow @remkopopma](https://img.shields.io/twitter/follow/remkopopma.svg?style=social)](https://twitter.com/intent/follow?screen_name=remkopopma) [![Follow @picocli](https://img.shields.io/twitter/follow/picocli.svg?style=social)](https://twitter.com/intent/follow?screen_name=picocli) # picocli - a mighty tiny command line interface Java command line parser with both an annotations API and a programmatic API, featuring usage help with ANSI colors, autocomplete and nested subcommands. In a single file, so you can include it _in source form_. This lets users run picocli-based applications without requiring picocli as an external dependency. How it works: annotate your class and picocli initializes it from the command line arguments, converting the input to strongly typed data. Supports git-like [subcommands](https://picocli.info/#_subcommands) (and nested [sub-subcommands](https://picocli.info/#_nested_sub_subcommands)), any option prefix style, POSIX-style [grouped short options](https://picocli.info/#_short_options), custom [type converters](https://picocli.info/#_custom_type_converters), [password options](http://picocli.info/#_interactive_password_options) and more. Parser [tracing](https://picocli.info/#_tracing) facilitates troubleshooting. Command-line [argument files](https://picocli.info/#AtFiles) (@-files) allow applications to handle very long command lines. Distinguishes between [named options](https://picocli.info/#_options) and [positional parameters](https://picocli.info/#_positional_parameters) and allows _both_ to be [strongly typed](https://picocli.info/#_strongly_typed_everything). [Multi-valued fields](https://picocli.info/#_multiple_values) can specify an exact number of parameters or a [range](https://picocli.info/#_arity) (e.g., `0..*`, `1..2`). Supports [Map options](https://picocli.info/#_maps) like `-Dkey1=val1 -Dkey2=val2`, where both key and value can be strongly typed. Generates polished and easily tailored [usage help](https://picocli.info/#_usage_help) and [version help](https://picocli.info/#_version_help), using [ANSI colors](https://picocli.info/#_ansi_colors_and_styles) where possible. Works with Java 5 or higher (but is designed to facilitate the use of Java 8 lambdas). Picocli-based command line applications can have [TAB autocompletion](https://picocli.info/autocomplete.html), interactively showing users what options and subcommands are available. When an option has [`completionCandidates`](https://picocli.info/#__code_completion_candidates_code_variable) or has an `enum` type, autocompletion can also suggest option values. Picocli can generate completion scripts for bash and zsh, and offers [`picocli-shell-jline2`](picocli-shell-jline2/README.md) and [`picocli-shell-jline3`](picocli-shell-jline3/README.md) modules with JLine `Completer` implementations for building interactive shell applications. Picocli-based applications can easily [integrate](https://picocli.info/#_dependency_injection) with Dependency Injection containers. ![Picocli Demo help message with ANSI colors](docs/images/picocli.Demo.png?raw=true) ### Releases * [Releases](https://github.com/remkop/picocli/releases) - Latest: 3.9.6 [Release Notes](https://github.com/remkop/picocli/releases/tag/v3.9.6) * Older: Picocli 3.0.0 [Release Notes](https://github.com/remkop/picocli/releases/tag/v3.0.0) * Older: Picocli 2.0 [Release Notes](https://github.com/remkop/picocli/releases/tag/v2.0.0) ### Documentation * [3.x User manual: https://picocli.info](https://picocli.info) * [3.x Quick Guide](https://picocli.info/quick-guide.html) * [2.x User manual](https://picocli.info/man/2.x) * [Command line autocompletion](https://picocli.info/autocomplete.html) * [API Javadoc](https://picocli.info/apidocs/) * [3.0 Programmatic API](https://picocli.info/picocli-3.0-programmatic-api.html) * [FAQ](https://github.com/remkop/picocli/wiki/FAQ) * [GraalVM AOT Compilation to Native Image](https://picocli.info/picocli-on-graalvm.html) ### Articles * [Migrating from Commons CLI to picocli](https://picocli.info/migrating-from-commons-cli.html). You won't regret it! :-) (also on: [DZone](https://dzone.com/articles/migrating-from-commons-cli-to-picocli) and [Java Code Geeks](https://www.javacodegeeks.com/2018/11/migrating-commons-cli-picocli.html)). * [Groovy 2.5 CliBuilder Renewal](https://picocli.info/groovy-2.5-clibuilder-renewal.html) (also on [blogs.apache.org](https://blogs.apache.org/logging/entry/groovy-2-5-clibuilder-renewal)). In two parts: [Part 1](https://picocli.info/groovy-2.5-clibuilder-renewal-part1.html) (also on: [DZone](https://dzone.com/articles/groovy-25-clibuilder-renewal), [Java Code Geeks](https://www.javacodegeeks.com/2018/06/groovy-clibuilder-renewal-part-1.html)), [Part 2](https://picocli.info/groovy-2.5-clibuilder-renewal-part2.html) (also on: [DZone](https://dzone.com/articles/groovy-25-clibuilder-renewal-part-2), [Java Code Geeks](https://www.javacodegeeks.com/2018/06/groovy-clibuilder-renewal-part-2.html)). * Micronaut user manual for running microservices [standalone with picocli](https://docs.micronaut.io/snapshot/guide/index.html#commandLineApps). * [Java Command-Line Interfaces (Part 30): Observations](http://marxsoftware.blogspot.jp/2017/11/java-cmd-line-observations.html) by Dustin Marx about picocli 2.0.1 (also on: [DZone](https://dzone.com/articles/java-command-line-interfaces-part-30-finale-observations), [Java Code Geeks](https://www.javacodegeeks.com/2017/11/java-command-line-interfaces-part-30-observations.html)) * [Java Command-Line Interfaces (Part 10): Picocli](http://marxsoftware.blogspot.jp/2017/08/picocli.html) by Dustin Marx about picocli 0.9.7 (also on: [DZone](https://dzone.com/articles/java-command-line-interfaces-part-10-picocli), [Java Code Geeks](https://www.javacodegeeks.com/2017/08/java-command-line-interfaces-part-10-picocli.html)) * [Picocli 2.0: Groovy Scripts on Steroids](https://picocli.info/picocli-2.0-groovy-scripts-on-steroids.html) (also on: [DZone](https://dzone.com/articles/picocli-v2-groovy-scripts-on-steroids), [Java Code Geeks](https://www.javacodegeeks.com/2018/01/picocli-2-0-groovy-scripts-steroids.html)) * [Picocli 2.0: Do More With Less](https://picocli.info/picocli-2.0-do-more-with-less.html) (also on: [DZone](https://dzone.com/articles/whats-new-in-picocli-20), [Java Code Geeks](https://www.javacodegeeks.com/2018/01/picocli-2-0-less.html)) * [Announcing picocli 1.0](https://picocli.info/announcing-picocli-1.0.html) (also on: [DZone](https://dzone.com/articles/announcing-picocli-10)) ### 中文 * [Picocli 2.0: Steroids上的Groovy脚本](https://picocli.info/zh/picocli-2.0-groovy-scripts-on-steroids.html) * [Picocli 2.0: 以少求多](https://picocli.info/zh/picocli-2.0-do-more-with-less.html) ### Mailing List Join the [picocli Google group](https://groups.google.com/d/forum/picocli) if you are interested in discussing anything picocli-related and receiving announcements on new releases. ### Related * Check out Thibaud Lepretre's [picocli Spring boot starter](https://github.com/kakawait/picocli-spring-boot-starter)! ### Credit [Reallinfo](https://github.com/reallinfo) designed the new picocli logo! Many thanks! ## Adoption * Picocli is now part of Groovy. From Groovy 2.5, all Groovy command line tools are picocli-based, and picocli is the underlying parser for Groovy's [CliBuilder DSL](http://groovy-lang.org/dsls.html#_clibuilder). * Picocli is now part of Micronaut. The Micronaut CLI has been rewritten with picocli, and Micronaut has dedicated support for running microservices [standalone with picocli](https://docs.micronaut.io/snapshot/guide/index.html#commandLineApps). * Picocli is now part of JUnit 5. JUnit 5.3 migrated its `ConsoleLauncher` from jopt-simple to picocli to support @-files (argument files); this helps users who need to specify many tests on the command line and run into system limitations. * Debian now offers a [libpicocli-java package](https://tracker.debian.org/pkg/picocli). Thanks to [Miroslav Kravec](https://udd.debian.org/dmd/?kravec.miroslav%40gmail.com). * Picocli is used in the Intuit [Karate](https://github.com/intuit/karate) standalone JAR / executable. * Picocli is part of [Ballerina](https://ballerina.io/). Ballerina uses picocli for all its command line utilities. * Picocli is used in the [CheckStyle](https://checkstyle.org/cmdline.html) standalone JAR / executable from Checkstyle 8.15. * Picocli is included in the [OpenJDK Quality Outreach](https://wiki.openjdk.java.net/display/quality/Quality+Outreach) list of Free Open Source Software (FOSS) projects that actively test against OpenJDK builds. Glad to see more people are using picocli. We must be doing something right. :-) ## Example Annotate fields with the command line parameter names and description. Optionally implement `Runnable` or `Callable` to delegate error handling and requests for usage help or version help to picocli. For example: ```java import picocli.CommandLine; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; import java.io.File; @Command(name = "example", mixinStandardHelpOptions = true, version = "Picocli example 3.0") public class Example implements Runnable { @Option(names = { "-v", "--verbose" }, description = "Verbose mode. Helpful for troubleshooting. " + "Multiple -v options increase the verbosity.") private boolean[] verbose = new boolean[0]; @Parameters(arity = "1..*", paramLabel = "FILE", description = "File(s) to process.") private File[] inputFiles; public void run() { if (verbose.length > 0) { System.out.println(inputFiles.length + " files to process..."); } if (verbose.length > 1) { for (File f : inputFiles) { System.out.println(f.getAbsolutePath()); } } } public static void main(String[] args) { CommandLine.run(new Example(), args); } } ``` If your command implements `Runnable`, all that is necessary to parse the command line and execute the command is a call to `CommandLine.run` with the command line parameters and the `Runnable` command. When the program is run on the command line, the command line arguments are converted to Java objects and assigned to the annotated fields. After the arguments are successfully parsed, picocli calls the command's `run` method. ```bash $ java Example -v inputFile1 inputFile2 2 files to process... ``` The `CommandLine.run` convenience method automatically prints the usage help message if the user requested help or when the input was invalid. ![Usage help message with ANSI colors](docs/images/ExampleUsageANSI.png?raw=true) If you want more control, you may be interested in the `CommandLine.parse` or `CommandLine.parseWithHandlers` methods. See the user manual for details. ## Usage Help with ANSI Colors and Styles Colors, styles, headers, footers and section headings are easily customized with annotations. For example: ![Longer help message with ANSI colors](docs/images/UsageHelpWithStyle.png?raw=true) See the [source code](https://github.com/remkop/picocli/blob/v0.9.4/src/test/java/picocli/Demo.java#L337). ## Usage Help API Picocli annotations offer many ways to customize the usage help message. If annotations are not sufficient, you can use picocli's [Help API](https://picocli.info/#_usage_help_api) to customize even further. For example, your application can generate help like this with a custom layout: ![Usage help message with two options per row](docs/images/UsageHelpWithCustomLayout.png?raw=true) See the [source code](https://github.com/remkop/picocli/blob/master/src/test/java/picocli/CustomLayoutDemo.java#L61). ## Download You can add picocli as an external dependency to your project, or you can include it as source. See the [source code](https://github.com/remkop/picocli/blob/master/src/main/java/picocli/CommandLine.java). Copy and paste it into a file called `CommandLine.java`, add it to your project, and enjoy! ### Gradle ``` compile 'info.picocli:picocli:3.9.6' ``` ### Maven ``` info.picocli picocli 3.9.6 ``` ### Scala SBT ``` libraryDependencies += "info.picocli" % "picocli" % "3.9.6" ``` ### Ivy ``` ``` ### Grape ```groovy @Grapes( @Grab(group='info.picocli', module='picocli', version='3.9.6') ) ``` ### Leiningen ``` [info.picocli/picocli "3.9.6"] ``` ### Buildr ``` 'info.picocli:picocli:jar:3.9.6' ``` picocli-3.9.6/RELEASE-NOTES.md000066400000000000000000006322761345764203000154670ustar00rootroot00000000000000# picocli Release Notes # Picocli 3.9.6 The picocli community is pleased to announce picocli 3.9.6. This release improves support for interactive (password) options: * interactive options can now use type `char[]` instead of String, to allow applications to null out the array after use so that sensitive information is no longer resident in memory * interactive options can be optionally interactive if configured with `arity = "0..1"` This is the fifty-second public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.9.6-new) * [Fixed issues](#3.9.6-fixes) * [Deprecations](#3.9.6-deprecated) * [Potential breaking changes](#3.9.6-breaking-changes) ## New and Noteworthy This release improves support for interactive (password) options: * interactive options can now use type `char[]` instead of String, to allow applications to null out the array after use so that sensitive information is no longer resident in memory * interactive options can be optionally interactive if configured with `arity = "0..1"` For example, if an application has these options: ```java @Option(names = "--user") String user; @Option(names = "--password", arity = "0..1", interactive = true) char[] password; ``` With the following input, the `password` field will be initialized to `"123"` without prompting the user for input: ``` --password 123 --user Joe ``` However, if the password is not specified, the user will be prompted to enter a value. In the following example, the password option has no parameter, so the user will be prompted to type in a value on the console: ``` --password --user Joe ``` ## Fixed issues * [#657] Support type `char[]` for interactive options. Thanks to [Lukáš Petrovický](https://github.com/triceo) for raising this issue. * [#536] Support optionally interactive options. Thanks to [Lukas Heumos](https://github.com/Zethson) for raising this issue. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.9.5 The picocli community is pleased to announce picocli 3.9.5. This release contains a critical workaround to protect against JVM crashes when running on RedHat Linux 3.10.0-327.44.2.el7.x86_64. Picocli 3.9.0 introduced a change in the heuristics for emitting ANSI escape characters. As part of this change, picocli may load the `org.fusesource.jansi.AnsiConsole` class from the JAnsi library when not running on Windows. This may crash the JVM (see [fusesource/jansi-native#17](https://github.com/fusesource/jansi-native/issues/17)). The workaround in this release is to only load the `AnsiConsole` class when running on Windows. Users using 3.9.0 and higher are strongly recommended to upgrade to 3.9.5 or later. This is the fiftieth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.9.5-new) * [Fixed issues](#3.9.5-fixes) * [Deprecations](#3.9.5-deprecated) * [Potential breaking changes](#3.9.5-breaking-changes) ## New and Noteworthy ## Fixed issues - [#630] Avoid loading `org.fusesource.jansi.AnsiConsole` when not running on Windows to avoid JVM crashes on non-Windows platforms. - [#632] ReflectionConfigGenerator now specifies the `allowWrite = true` attribute for final fields. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.9.4 The picocli community is pleased to announce picocli 3.9.4. This release contains bugfixes and enhancements. From this release, `enum`-typed options and positional parameters that are multi-value can be stored in `EnumSet` collections (in addition to other Collections, arrays and Maps). Also, a better error message is now shown when unknown options are encountered while processing clustered short options. The new error message includes both the failing part and the original command line argument. Bugfixes: * `ReflectionConfigGenerator` incorrectly listed superclass fields as fields of the concrete subclass, causing "GraalVM error: Error parsing reflection configuration in json" when creating a native image. * Method subcommands in commands that subclass another command caused `InitializationException`. This is the forty-nineth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.9.4-new) * [Fixed issues](#3.9.4-fixes) * [Deprecations](#3.9.4-deprecated) * [Potential breaking changes](#3.9.4-breaking-changes) ## New and Noteworthy ## Fixed issues - [#628] Add support for collecting `enum` multi-value options and positional parameters in `EnumSet<>` collections. Thanks to [Lee Atkinson](https://github.com/leeatkinson) for raising this. - [#619] Bugfix: Method subcommands in commands that subclass another command caused `InitializationException`: "Another subcommand named 'method' already exists...". Thanks to [PorygonZRocks](https://github.com/PorygonZRocks) for the bug report. - [#622] Bugfix: `ReflectionConfigGenerator` incorrectly listed superclass fields as fields of the concrete subclass, causing "GraalVM error: Error parsing reflection configuration in json". Thanks to [Sebastian Thomschke](https://github.com/sebthom) for the bug report. - [#623] `ReflectionConfigGenerator` now generates json in alphabetic order. - [#627] Improve error message for unknown options when processing clustered short options. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.9.3 The picocli community is pleased to announce picocli 3.9.3. This release contains bugfixes and enhancements. This is the forty-eight public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.9.3-new) * [Fixed issues](#3.9.3-fixes) * [Deprecations](#3.9.3-deprecated) * [Potential breaking changes](#3.9.3-breaking-changes) ## New and Noteworthy ## Fixed issues - [#613] Enhancement: Improve picocli heuristics for unmatched options: single-character arguments that don't exactly match options (like `-`) should be considered positional parameters. Thanks to [Oliver Weiler](https://github.com/helpermethod) for the bug report. - [#615] Bugfix: Opaque stacktrace for "%" in Option description. Thanks to [petermr](https://github.com/petermr) for the bug report. - [#616] Bugfix: showDefaultValues=true with defaultValueProvider did not render defaultValues in usage help. Thanks to [Sebastian Thomschke](https://github.com/sebthom) for the bug report. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.9.2 The picocli community is pleased to announce picocli 3.9.2. This release contains bugfixes and enhancements. Picocli now has a mailing list `picocli at googlegroups dot com`. Alternatively visit the [picocli Google group](https://groups.google.com/d/forum/picocli) web interface. The user manual has improved documentation for internationalization and localization, and the section on Dependency Injection now has a Spring Boot example and link to the Micronaut user manual. Bugfixes: `AutoComplete` now uses the specified `IFactory` correctly for `CommandLine`; defaulting `usageHelp` or `versionHelp` options no longer prevents validation of required options; and usage help for booleans options with `arity = "1"` now correctly show the option parameter in the synopsis. Many thanks to the many members of the picocli community who contributed pull requests, bug reports and participated in discussions! This is the forty-seventh public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.9.2-new) * [Fixed issues](#3.9.2-fixes) * [Deprecations](#3.9.2-deprecated) * [Potential breaking changes](#3.9.2-breaking-changes) ## New and Noteworthy Picocli now has a mailing list `picocli at googlegroups dot com`. Alternatively visit the [picocli Google group](https://groups.google.com/d/forum/picocli) web interface. The user manual has improved documentation for internationalization and localization. Dependency Injection is now a top-level section and now has a Spring Boot example and link to the Micronaut user manual. ## Fixed issues - [#602] Make `CommandLine` in `AutoComplete` use correct `IFactory` implementation. Thanks to [Mikołaj Krzyżanowski](https://github.com/MikolajK) for the pull request. - [#608] Bugfix: defaulting `usageHelp` or `versionHelp` options incorrectly prevented validation of required options and positional parameters. Thanks to [Pietro Braione](https://github.com/pietrobraione) for the bug report. - [#612] Bugfix: Usage help for booleans options with `arity = "1"` now correctly show the option parameter in synopsis. Thanks to [prewersk](https://github.com/prewersk) for the bug report. - [#606] Doc: Added subcommand example. Thanks to [Andreas Deininger](https://github.com/deining) for the pull request. - [#605] Doc: Improved documentation for internationalization and localization. Thanks to [Andreas Deininger](https://github.com/deining) for raising this. - [#604] Doc: Improve user manual section on Dependency Injection: add Spring Boot example. Thanks to [Alistair Rutherford](https://github.com/alistairrutherford) for the example code. - [#610] Build: add JDKs to Travis CI build. - [#609] Created mailing list `picocli at googlegroups dot com`: [picocli Google group](https://groups.google.com/d/forum/picocli). ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.9.1 The picocli community is pleased to announce picocli 3.9.1. The `picocli.AutoComplete` application no longer calls `System.exit()` unless requested by setting system property `picocli.autocomplete.systemExitOnError` or `picocli.autocomplete.systemExitOnSuccess` to any value other than `false`. Applications that rely on the exit codes introduced in picocli 3.9.0 need to set these system properties. This release adds support for quoted map keys with embedded '=' characters. This release contains bugfixes and enhancements. This is the forty-sixth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.9.1-new) * [Fixed issues](#3.9.1-fixes) * [Deprecations](#3.9.1-deprecated) * [Potential breaking changes](#3.9.1-breaking-changes) ## New and Noteworthy ## Fixed issues - [#592] Error message now shows `enum` constant names, not `toString()` values, after value mismatch. Thanks to [startewho](https://github.com/startewho) for the bug report. - [#591] Replace some String concatenation in `picocli.AutoComplete` with StringBuilder. Thanks to [Sergio Escalante](https://github.com/sergioescala) for the pull request. - [#594] Add support for quoted map keys with embedded '=' characters. Thanks to [Pubudu Fernando](https://github.com/pubudu91) for the suggestion. - [#596] `picocli.AutoComplete` should not call `System.exit()` unless requested. Thanks to [Markus Heiden](https://github.com/markusheiden), [Bob Tiernay](https://github.com/bobtiernay-okta) and [RobertZenz](https://github.com/RobertZenz) for analysis and ideas contributing to the solution. - [#593] Use Gradle Bintray Plugin to publish artifacts to Bintray. ## Deprecations No features were deprecated in this release. ## Potential breaking changes The `picocli.AutoComplete` application no longer calls `System.exit()` unless requested by setting system property `picocli.autocomplete.systemExitOnError` or `picocli.autocomplete.systemExitOnSuccess` to any value other than `false`. Applications that rely on the exit codes introduced in picocli 3.9.0 need to set these system properties. The new support for quoted map keys with embedded '=' characters [#594] may inpact some existing applications. If `CommandLine::setTrimQuotes()` is set to `true`, quotes are now removed from map keys and map values. This did not use to be the case. For example: ```java class App { @Option(names = "-p") Map map; } ``` When `CommandLine::setTrimQuotes()` was set to `true`, given input like the below: ``` -p AppOptions="-Da=b -Dx=y" ``` The above used to result in a map with key `AppOptions` and value `"-Da=b -Dx=y"` (including the quotes), but the same program and input now results in a map with key `AppOptions` and value `-Da=b -Dx=y` (without quotes). Also, when `CommandLine::setTrimQuotes()` is `false` (the default), input like the below will now cause a `ParameterException` ("value should be in KEY=VALUE format"): ``` -p "AppOptions=-Da=b -Dx=y" ``` Prior to this release, the above was silently ignored (no errors but also no key-value pairs in the resulting map). # Picocli 3.9.0 The picocli community is pleased to announce picocli 3.9.0. This release contains bugfixes and enhancements in the main picocli module, and adds a new module: `picocli-shell-jline3`. The new module Picocli Shell JLine3 (`picocli-shell-jline3`) contains components and documentation for building interactive shell command line applications with JLine 3 and picocli. This release contains API enhancements to allow customization of the usage help message: * help section renderers can be added, replaced or removed * help section keys to reorder sections in the usage help message * help factory to create custom `Help` instances * option order attribute to reorder options in the usage help message option list This release also has improved heuristics to decide whether ANSI escape codes should be emitted or not. The simplified @-file (argument file) format is now fully compatible with JCommander: empty lines are ignored and comments may start with leading whitespace. The `picocli.Autocompletion` application now accepts a parameter specifying a custom factory, and returns a non-zero exit code on error, to facilitate incorporating it into the build. Bug fixes in this release: * `@Command` method options and positional parameter values are now cleared correctly when reusing a `CommandLine` instance * the default exception handler now correctly respects the exit code for all exceptions Finally, this release improves internal quality and robustness by increasing the test code coverage. About 300 tests were added to bring the total to 1300+ tests. This improved line coverage to 98% (was 88%) and complexity coverage to 98% (was 82%). This is the forty-fifth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.9.0-new) * [Fixed issues](#3.9.0-fixes) * [Deprecations](#3.9.0-deprecated) * [Potential breaking changes](#3.9.0-breaking-changes) ## New and Noteworthy ### Help Section Renderer API This release introduces new API to facilitate customizing the usage help message: `IHelpFactory` allows applications to plug in `Help` subclasses, and `IHelpSectionRenderer` allows applications to add custom sections to the usage help message, or redefine existing sections. The usage help message is no longer hard-coded, but is now constructed from the section renderers defined in `CommandLine::getHelpSectionMap` (or `UsageMessageSpec::sectionMap` for a single `CommandSpec`). By default this map contains the predefined section renderers: ```java // The default section renderers delegate to methods in Help for their implementation // (using Java 8 lambda notation for brevity): Map map = new HashMap<>(); map.put(SECTION_KEY_HEADER_HEADING, help -> help.headerHeading()); map.put(SECTION_KEY_HEADER, help -> help.header()); //e.g. Usage: map.put(SECTION_KEY_SYNOPSIS_HEADING, help -> help.synopsisHeading()); //e.g. [OPTIONS] [COMMAND-OPTIONS] [ARGUMENTS] map.put(SECTION_KEY_SYNOPSIS, help -> help.synopsis(help.synopsisHeadingLength())); //e.g. %nDescription:%n%n map.put(SECTION_KEY_DESCRIPTION_HEADING, help -> help.descriptionHeading()); //e.g. {"Converts foos to bars.", "Use options to control conversion mode."} map.put(SECTION_KEY_DESCRIPTION, help -> help.description()); //e.g. %nPositional parameters:%n%n map.put(SECTION_KEY_PARAMETER_LIST_HEADING, help -> help.parameterListHeading()); //e.g. [FILE...] the files to convert map.put(SECTION_KEY_PARAMETER_LIST, help -> help.parameterList()); //e.g. %nOptions:%n%n map.put(SECTION_KEY_OPTION_LIST_HEADING, help -> help.optionListHeading()); //e.g. -h, --help displays this help and exits map.put(SECTION_KEY_OPTION_LIST, help -> help.optionList()); //e.g. %nCommands:%n%n map.put(SECTION_KEY_COMMAND_LIST_HEADING, help -> help.commandListHeading()); //e.g. add adds the frup to the frooble map.put(SECTION_KEY_COMMAND_LIST, help -> help.commandList()); map.put(SECTION_KEY_FOOTER_HEADING, help -> help.footerHeading()); map.put(SECTION_KEY_FOOTER, help -> help.footer()); ``` Applications can add, remove or replace sections in this map. The `CommandLine::getHelpSectionKeys` method (or `UsageMessageSpec::sectionKeys` for a single `CommandSpec`) returns the section keys in the order that the usage help message should render the sections. The default keys are (in order): 1. SECTION_KEY_HEADER_HEADING 1. SECTION_KEY_HEADER 1. SECTION_KEY_SYNOPSIS_HEADING 1. SECTION_KEY_SYNOPSIS 1. SECTION_KEY_DESCRIPTION_HEADING 1. SECTION_KEY_DESCRIPTION 1. SECTION_KEY_PARAMETER_LIST_HEADING 1. SECTION_KEY_PARAMETER_LIST 1. SECTION_KEY_OPTION_LIST_HEADING 1. SECTION_KEY_OPTION_LIST 1. SECTION_KEY_COMMAND_LIST_HEADING 1. SECTION_KEY_COMMAND_LIST 1. SECTION_KEY_FOOTER_HEADING 1. SECTION_KEY_FOOTER This ordering may be modified with the `CommandLine::setHelpSectionKeys` setter method (or `UsageMessageSpec::sectionKeys(List)` for a single `CommandSpec`). ### Option `order` Attribute Options are sorted alphabetically by default, but this can be switched off by specifying `@Command(sortOptions = false)` on the command declaration. This displays options in the order they are declared. However, when mixing `@Option` methods and `@Option` fields, options do not reliably appear in declaration order. The `@Option(order = )` attribute can be used to explicitly control the position in the usage help message at which the option should be shown. Options with a lower number are shown before options with a higher number. ### New Module `picocli-shell-jline3` Picocli Shell JLine3 contains components and documentation for building interactive shell command line applications with JLine 3 and picocli. This release contains the `picocli.shell.jline3.PicocliJLineCompleter` class. `PicocliJLineCompleter` is a small component that generates completion candidates to allow users to get command line TAB auto-completion for a picocli-based application running in a JLine 3 shell. It is similar to the class with the same name in the `picocli.shell.jline2` package in the `picocli-shell-jline2` module. See the module's [README](https://github.com/remkop/picocli/blob/master/picocli-shell-jline3/README.md) for more details. ### Improved ANSI Heuristics This release has improved heuristics to decide whether ANSI escape codes should be emitted or not. Support was added for the following environment variables to control enabling ANSI: * [`NO_COLOR`](https://no-color.org/) * [`CLICOLOR_FORCE`](https://bixense.com/clicolors/) * [`CLICOLOR`](https://bixense.com/clicolors/) * [`ConEmuANSI`](https://conemu.github.io/en/AnsiEscapeCodes.html#Environment_variable) * [`ANSICON`](https://github.com/adoxa/ansicon/blob/master/readme.txt) ## Fixed issues - [#574] Add `picocli-shell-jline3` module. Thanks to [mattirn](https://github.com/mattirn) for the pull request. - [#587] Enhance `picocli-shell-jline3` example by using JLine's `DefaultParser` to split lines into arguments. Thanks to [mattirn](https://github.com/mattirn) for the pull request. - [#567] Usage message customization API initial implementation. Thanks to [Christian Helmer](https://github.com/SysLord) for the pull request. - [#530] Added API for easily customizing the usage help message. Thanks to [stechio](https://github.com/stechio) for raising the request and productive discussions. - [#569] Facilitate customization of the synopsis: split `Help.detailedSynopsis()` into protected methods. - [#508] Annotation API: added `@Option(order = )` attribute to allow explicit control of option ordering in the usage help message; useful when mixing methods and fields with `@Option` annotation. - [#588] Added method `CommandSpec.names` returning both `name` and `aliases`. - [#578] Add API for simplified @files argument files. - [#573] Make simplified @files JCommander-compatible: ignore empty lines and comments starting with whitespace. Thanks to [Lukáš Petrovický](https://github.com/triceo) for the pull request with test to reproduce the issue. - [#572] `CommandSpec.addMethodSubcommands` now throws `picocli.CommandLine.InitializationException` instead of `java.lang.UnsupportedOperationException` when the user object of the parent command is a `java.lang.reflect.Method`. - [#581] Added support for ConEmu, ANSICON and other environment variables to improve the ANSI heuristics. Documented the heuristics in the user manual. - [#579] Improved `AutoComplete` error message when not overwriting existing files. - [#585] `picocli.AutoComplete` now accepts a parameter specifying a custom `IFactory` implementation. Thanks to [Bob Tiernay](https://github.com/bobtiernay-okta) for the suggestion. - [#582] `picocli.AutoComplete` now returns a non-zero return code on error. Thanks to [Bob Tiernay](https://github.com/bobtiernay-okta) for the suggestion. - [#570] Bugfix: Command method options and positional parameter Object values are now cleared correctly when reusing CommandLine. Thanks to [Christian Helmer](https://github.com/SysLord) for the pull request. - [#576] Bugfix: fixed StringIndexOutOfBoundsException in shell-jline2 completion when cursor was before `=` when option parameter was attached to option name. - [#583] Bugfix: Default exception handler now exits on exception if exitCode was set, regardless of exception type. - [#584] Add documentation for generating autocompletion script during a Maven build. Thanks to [Bob Tiernay](https://github.com/bobtiernay-okta). - [#586] Replace Ansi.Text.clone() with copy constructor. - [#571] Improve test code coverage. Added ~300 tests to bring the total to 1300+ tests. Improved line coverage to 98% (was 88%) and complexity coverage to 98% (was 82%). - [#590] Fail the build if test coverage falls below minimum threshold. - [#589] Fix index.adoc to eliminate warnings; suppress javadoc warnings. - [#566] Add example showing how to customize the usage help message to show the full command tree including nested subcommands. Thanks to [lgawron](https://github.com/lgawron) for the request. ## Deprecations No features were deprecated in this release. ## Potential breaking changes `CommandSpec.addMethodSubcommands` now throws `InitializationException` instead of `java.lang.UnsupportedOperationException` when the user object of the parent command is a `java.lang.reflect.Method`. AutoComplete application now prints different error message when not overwriting existing script files. This may break tests that verify the console output. # Picocli 3.8.2 The picocli community is pleased to announce picocli 3.8.2. This release contains bugfixes only. When running a native image with Graal, ANSI colors are now shown correctly. This is the forty-forth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.8.2-new) * [Fixed issues](#3.8.2-fixes) * [Deprecations](#3.8.2-deprecated) * [Potential breaking changes](#3.8.2-breaking-changes) ## New and Noteworthy ## Fixed issues - [#557] Bugfix: No colors are shown when compiling to a native image with Graal on MacOS. Thanks to [Oliver Weiler](https://github.com/helpermethod) for the bug report. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This is a patch release and has no breaking changes. # Picocli 3.8.1 The picocli community is pleased to announce picocli 3.8.1. This release contains bugfixes and minor enhancements. Command methods explicitly throwing a `ParametersException` is now correctly handled by picocli, showing the error message and the usage help message. This release adds support for JCommander-style argument files (one argument per line, no quoting) and better tracing. Many thanks to the many members of the picocli community who contributed! This is the forty-third public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.8.1-new) * [Fixed issues](#3.8.1-fixes) * [Deprecations](#3.8.1-deprecated) * [Potential breaking changes](#3.8.1-breaking-changes) ## New and Noteworthy ### Simplified Argument Files In this argument file format every line (except comment lines) is interpreted as a single argument. Arguments containing whitespace do not need to be quoted, but it is not possible to have arguments with embedded newlines. Set system property `picocli.useSimplifiedAtFiles` without a value or with value `"true"` (case-insensitive) to enable this simpler argument file format. This format is similar to the way JCommander processes argument files, which makes it easier for command line applications to migrate from JCommander to picocli. ### Improved Tracing The following information has been added to the tracing output in this release: * Version information (picocli version, java version, os version), logged at INFO level * ANSI enabled status, logged at DEBUG level * Log at DEBUG level when a Map or Collection binding for an option or positional parameter is initialized with a new instance * Log at DEBUG level when parameters are being split (into how many parts, show resulting parts) ## Fixed issues - [#551] Enhancement: Add support for JCommander-style argument files (one argument per line, no quoting). Thanks to [Lukáš Petrovický](https://github.com/triceo) for the bug report and unit tests. - [#562] Enhancement: Allow for enabling quote trimming via system property `picocli.trimQuotes`. Thanks to [Lukáš Petrovický](https://github.com/triceo) for the pull request. - [#560] Enhancement: Better tracing. - [#554] Bugfix: Convenience method error handling was broken for command methods that explicitly throw an ParameterException: InvocationTargetException hides the ParameterException. Thanks to [SysLord](https://github.com/SysLord) for the bug report. - [#553] Doc: Fix broken link to CommandLine.java source code. Thanks to [Simon Legner](https://github.com/simon04) for the pull request. - [#563] Doc: Improve documentation for explicitly showing usage help from subcommands. Thanks to [Steve Johnson](https://github.com/Blatwurst) for raising this issue. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This is a patch release and has no breaking changes. # Picocli 3.8.0 The picocli community is pleased to announce picocli 3.8.0. This release contains bugfixes and minor enhancements. `@Command` methods now support `@Mixin` parameters. `OverwrittenOptionException` now has an accessor for the `ArgSpec` that was overwritten. The `ReflectionConfigGenerator` tool in the `picocli-codegen` module now correctly generates configuration for `@Mixin` fields. Many thanks to the many members of the picocli community who contributed! This is the forty-second public release. Picocli follows [semantic versioning](http://semver.org/). (This release could have been called 3.7.1 except that it has a minor additional API change, which means it cannot be called a patch release by semver rules.) ## Table of Contents * [New and noteworthy](#3.8.0-new) * [Fixed issues](#3.8.0-fixes) * [Deprecations](#3.8.0-deprecated) * [Potential breaking changes](#3.8.0-breaking-changes) ## New and Noteworthy ### Mixin Support in `@Command` Methods `@Command` methods now accept `@Mixin` parameters. All options and positional parameters defined in the mixin class are added to the command. Example: ```java class CommonParams { @Option(names = "-x") int x; @Option(names = "-y") int y; } class App { @Command public void doit(@Mixin CommonParams params, @Option(names = "-z") int z) {} } ``` In the above example, the `-x` and `-y` options are added to the other options of the `doit` command. ## Fixed issues - [#525] Enhancement: Allow `@Mixin` parameters in `@Command` methods. Thanks to [Paul Horn](https://github.com/knutwalker) for the pull request. - [#532] Enhancement: `OverwrittenOptionException` now has an accessor for the `ArgSpec` that was overwritten. Thanks to [Steven Fontaine](https://github.com/acid1103) for the pull request. - [#524] Enhancement/Bugfix: `ReflectionConfigGenerator` in `picocli-codegen` should generate configuration for `@Mixin` fields. Thanks to [Paul Horn](https://github.com/knutwalker) for the pull request. - [#301] Enhancement/Bugfix: The subcommand listing now correctly renders `%n` as line breaks in the brief description for each subcommand. Thanks to [Vlad Topala](https://github.com/topalavlad) for the pull request. - [#523] Bugfix: Array should be initialized before calling setter method. Thanks to [Paul Horn](https://github.com/knutwalker) for the pull request. - [#527] Bugfix: Quoting logic did not work for some Unicode code points. - [#531] Bugfix: Usage help should not show space between short option name and parameter (for options that only have a short name). - [#538] Bugfix: Command methods and interface methods should pass `null` for unmatched primitive wrapper options. - [#547] Bugfix: Fix infinite loop when print help. Thanks to [Patrick Kuo](https://github.com/patrickkuo) for the pull request. - [#528] Doc: Javadoc for xxxHandler API referred to non-existant prototypeReturnValue. - [#545] Doc: Include mention of command methods for options using collections. Thanks to [Bob Tiernay](https://github.com/bobtiernay-okta) for the pull request. ## Deprecations No features were deprecated in this release. ## Potential breaking changes ### Help Layout The usage help no longer shows a space between short option names and the parameter (for options that only have a short name). This may break tests that rely on the exact output format. Before: ``` Usage: times [-l=] [-r=] -l= -r= ``` After: ``` Usage: times [-l=] [-r=] -l= -r= ``` ### Unmatched Primitive Wrapper Type Options Another behavioral change is that command methods now pass in `null` for primitive wrapper options that were not matched on the command line. This impacts methods annotated with `@Command`, and interface methods annotated with `@Option`. Classes annotated with `@Command` already behaved like this and this has not changed. This behaviour is now consistent for all annotation-based and programmatic ways of defining commands. # Picocli 3.7.0 The picocli community is pleased to announce picocli 3.7.0. This release contains bugfixes and enhancements in the main picocli module, and adds two new modules: `picocli-codegen` and `picocli-shell-jline2`. Picocli Code Generation (`picocli-codegen`) contains tools for generating source code, documentation and configuration files for picocli-based applications. Picocli Shell JLine2 (`picocli-shell-jline2`) contains components and documentation for building interactive shell command line applications with JLine 2 and picocli. Many thanks to the many members of the picocli community who contributed! This is the forty-first public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.7.0-new) * [Fixed issues](#3.7.0-fixes) * [Deprecations](#3.7.0-deprecated) * [Potential breaking changes](#3.7.0-breaking-changes) ## New and Noteworthy ### Improved Parsing of Quoted Values This release improves parser behaviour of quoted arguments: * Quotes around command line parameters are now preserved by default (previously they were removed). This can be configured with `CommandLine::setTrimQuotes`. * When [splitting](https://picocli.info/#_split_regex) parameters, quoted strings are no longer split. This can be configured with `CommandLine::setSplitQuotedStrings`. Example: ``` @Option(names = "-x", split = ",") String[] parts; ``` Given input like below: ``` -x a,b,"c,d,e",f,"xxx,yyy" ``` This results in the `parts` array having the following values: ``` a b "c,d,e" f "xxx,yyy" ``` ### New Module `picocli-codegen` Picocli Code Generation contains tools for generating source code, documentation and configuration files for picocli-based applications. This release contains the `ReflectionConfigGenerator` class. `ReflectionConfigGenerator` generates a JSON String with the program elements that will be accessed reflectively in a picocli-based application, in order to compile this application ahead-of-time into a native executable with GraalVM. The output of `ReflectionConfigGenerator` is intended to be passed to the `-H:ReflectionConfigurationFiles=/path/to/reflectconfig` option of the `native-image` GraalVM utility. This allows picocli-based applications to be compiled to a native image. See [Picocli on GraalVM: Blazingly Fast Command Line Apps](https://github.com/remkop/picocli/wiki/Picocli-on-GraalVM:-Blazingly-Fast-Command-Line-Apps) for details. The module's [README](https://github.com/remkop/picocli/blob/master/picocli-codegen/README.md) explains how to configure your build to generate the configuration file automatically as part of your build. ### New Module `picocli-shell-jline2` Picocli Shell JLine2 contains components and documentation for building interactive shell command line applications with JLine 2 and picocli. This release contains the `PicocliJLineCompleter` class. `PicocliJLineCompleter` is a small component that generates completion candidates to allow users to get command line TAB auto-completion for a picocli-based application running in a JLine 2 shell. See the module's [README](https://github.com/remkop/picocli/blob/master/picocli-shell-jline2/README.md) for more details. ## Fixed issues - [#503] Build: Upgrade to gradle 4.10.2. - [#497] add module `picocli-shell-jline2` for components and documentation for building interactive shell command line applications with JLine 2 and picocli. - [#499] add module `picocli-codegen` for tools to generate documentation, configuration, source code and other files from a picocli model - [#410] add `ReflectionConfigGenerator` class for GraalVM `native-image` - [#513] Enhancement: Simplify AutoCompletion script generator code. - [#481] Enhancement: Add `@Command(usageHelpWidth = )` annotation attribute. - [#379] Option with split property should not split quoted strings. Thanks to [Markus Kramer](https://github.com/MarkusKramer) for the feature request. - [#514] Bugfix/Enhancement: picocli no longer removes opening and closing quotes around arguments by default. This is configurable with `CommandLine::setTrimQuotes`. Thanks to [mshatalov](https://github.com/mshatalov) for the bug report. - [#509] Bugfix: Long boolean options with arity 0 should not allow parameters. Thanks to [Adam Zegelin](https://github.com/zegelin) for the bug report. - [#510] Documentation: Fix broken link for moved example files. Thanks to [Anthony Keenan](https://github.com/anthonykeenan) for the pull request. - [#24] Documentation: Added Chinese translations of "Picocli 2.0 Do More With Less" and "Picocli 2.0 Groovy Scripts on Steroids". ## Deprecations No features were deprecated in this release. ## Potential breaking changes From this release, picocli no longer removes opening and closing quotes around arguments by default. This is configurable with `CommandLine::setTrimQuotes`. # Picocli 3.6.1 The picocli community is pleased to announce picocli 3.6.1. This release contains bugfixes, minor enhancements and documentation improvements. ANSI is automatically enabled on Windows if Jansi's `AnsiConsole` has been installed. It is now possible to selectively avoid loading type converters with reflection. Bugfix: Enum values were not rendered in `${COMPLETION-CANDIDATES}` for collection type options. Many thanks to the many members of the picocli community who contributed! This is the fortieth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.6.1-new) * [Fixed issues](#3.6.1-fixes) * [Deprecations](#3.6.1-deprecated) * [Potential breaking changes](#3.6.1-breaking-changes) ## New and Noteworthy ## Fixed issues - [#487] Enhancement: Auto-completion script should return from `generateOptionsSwitch` immediately if there is nothing to generate. Thanks to [David Walluck](https://github.com/dwalluck) for the pull request. - [#483][#486] Enhancement: Improve `Help.Ansi.AUTO`: automatically enable ANSI on Windows if Jansi's `AnsiConsole` has been installed. Thanks to [Philippe Charles](https://github.com/charphi) for the pull request. - [#491] Enhancement: Improve `Help.Ansi.AUTO` cygwin/msys detection on Windows. - [#451] Enhancement: Selectively disable reflective type converter registration. Thanks to [Paolo Di Tommaso](https://github.com/pditommaso) for the suggestion. - [#488] Doc: Clarify in user manual that `CommandLine.setPosixClusteredShortOptionsAllowed(false)` means that option parameters cannot be attached to the option name. Thanks to [Maryam Ziyad](https://github.com/MaryamZi) for raising this. - [#492][#493] Doc: Add section on `@Command(aliases)` attribute to user manual. Thanks to [marinier](https://github.com/marinier) for the pull request. - [#494] Bugfix: Enum values were not rendered in `${COMPLETION-CANDIDATES}` for collection type options. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.6.0 The picocli community is pleased to announce picocli 3.6.0. This release contains new features, bugfixes and enhancements. New interface: `IDefaultProvider` allows you to get default values from a configuration file or some other central place. `@Command` Methods: From this release, methods can be annotated with `@Command`. The method parameters provide the command options and parameters. Internationalization: from this release, usage help message sections and the description for options and positional parameters can be specified in a resource bundle. A resource bundle can be set via annotations and programmatically. The error message on invalid user input has been improved. This release also contains various improvements the the bash/zsh completion script generation to be more consistent with standard completion on these shells. Many thanks to the many members of the picocli community who raised issues and contributed solutions! This is the thirty-nineth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.6.0-new) * [Fixed issues](#3.6.0-fixes) * [Deprecations](#3.6.0-deprecated) * [Potential breaking changes](#3.6.0-breaking-changes) ## New and Noteworthy ### Default Provider This release allows you to specify a default provider in the `@Command` annotation: ```java @Command(defaultValueProvider = MyDefaultProvider.class) class MyCommand // ... ``` The default provider allows you to get default values from a configuration file or some other central place. Default providers need to implement the `picocli.CommandLine.IDefaultValueProvider` interface: ```java public interface IDefaultValueProvider { /** * Returns the default value for an option or positional parameter or {@code null}. * The returned value is converted to the type of the option/positional parameter * via the same type converter used when populating this option/positional * parameter from a command line argument. * * @param argSpec the option or positional parameter, never {@code null} * @return the default value for the option or positional parameter, or {@code null} if * this provider has no default value for the specified option or positional parameter * @throws Exception when there was a problem obtaining the default value */ String defaultValue(ArgSpec argSpec) throws Exception; } ``` ### `@Command` Methods From picocli 3.6, methods can be annotated with `@Command`. The method parameters provide the command options and parameters. For example: ```java class Cat { public static void main(String[] args) { CommandLine.invoke("cat", Cat.class, args); } @Command(description = "Concatenate FILE(s) to standard output.", mixinStandardHelpOptions = true, version = "3.6.0") void cat(@Option(names = {"-E", "--show-ends"}) boolean showEnds, @Option(names = {"-n", "--number"}) boolean number, @Option(names = {"-T", "--show-tabs"}) boolean showTabs, @Option(names = {"-v", "--show-nonprinting"}) boolean showNonPrinting, @Parameters(paramLabel = "FILE") File[] files) { // process files } } ``` The usage help of the above command looks like this: ``` Usage: cat [-EhnTvV] [FILE...] Concatenate FILE(s) to standard output. [FILE...] -E, --show-ends -h, --help Show this help message and exit. -n, --number -T, --show-tabs -v, --show-nonprinting -V, --version Print version information and exit. ``` See below for an example that uses a resource bundle to define usage help descriptions outside the code. For positional parameters, the `@Parameters` annotation may be omitted on method parameters. TIP: If compiled with the `-parameters` flag on Java 8 or higher, the `paramLabel` of positional parameters is obtained from the method parameter name using reflection instead of the generic arg0, arg1, etc. #### Subcommand Methods If the enclosing class is annotated with `@Command`, method commands are added as subcommands to the class command, unless the class command has attribute `@Command(addMethodSubcommands = false)`. For example: ```java @Command(name = "git", mixinStandardHelpOptions = true, version = "picocli-3.6.0") class Git { @Option(names = "--git-dir", descriptionKey = "GITDIR") Path path; @Command void commit(@Option(names = {"-m", "--message"}) String commitMessage, @Option(names = "--squash", paramLabel = "") String squash, @Parameters(paramLabel = "") File[] files) { // ... implement business logic } } ``` Use `@Command(addMethodSubcommands = false)` on the class `@Command` annotation if the `@Command`-annotated methods in this class should not be added as subcommands. The usage help of the `git commit` command looks like this: ``` Usage: git commit [--squash=] [-m=] [...] [...] --squash= -m, --message= ``` ### Internationalization From version 3.6, usage help message sections and the description for options and positional parameters can be specified in a resource bundle. A resource bundle can be set via annotations and programmatically. Annotation example: ```java @Command(name = "i18n-demo", resourceBundle = "my.org.I18nDemo_Messages") class I18nDemo {} ``` Programmatic example: ```java @Command class I18nDemo2 {} CommandLine cmd = new CommandLine(new I18nDemo2()); cmd.setResourceBundle(ResourceBundle.getBundle("my.org.I18nDemo2_Messages")); ``` Resources for multiple commands can be specified in a single ResourceBundle. Keys and their value can be shared by multiple commands (so you don't need to repeat them for every command), but keys can be prefixed with `fully qualified command name + "."` to specify different values for different commands. The most specific key wins. This is especially convenient for `@Command` methods where long description annotations would make the code less easy to read. You can use a resource bundle to move the descriptions out of the code: ``` # shared between all commands help = Show this help message and exit. version = Print version information and exit. # command-specific strings git.usage.description = Version control system git.GITDIR = Set the path to the repository git.commit.usage.description = Record changes to the repository git.commit.message = Use the given as the commit message. git.commit.squash = Construct a commit message for use with rebase --autosquash. git.commit.[0..*] = The files to commit. ``` With this resource bundle, the usage help for the above `git commit` command looks like this: ``` Usage: git commit [--squash=] [-m=] [...] Record changes to the repository [...] The files to commit. --squash= Construct a commit message for use with rebase --autosquash. -m, --message= Use the given as the commit message. ``` ### Improved Error Messages The error messages on invalid input have been improved. For example: Previously, if an argument could not be converted to a primitive type, the error looked like this: `Could not convert 'abc' to int for option '-num': java.lang.NumberFormatException: For input string: \"abc\"` The new error message for primitive types looks like this: `Invalid value for option '-num': 'abc' is not an int` Previously, if an argument could not be converted to an enum, the error looked like this: `Could not convert 'xyz' to TimeUnit for option '-timeUnit': java.lang.IllegalArgumentException: No enum constant java.util.concurrent.TimeUnit.xyz` The new error message for enums looks like this: `Invalid value for option '-timeUnit': expected one of [NANOSECONDS, MILLISECONDS, MICROSECONDS, SECONDS, MINUTES, HOURS, DAYS] but was 'xyz'` ## Fixed issues - [#321] API: Add support for IDefaultValueProvider. Thanks to [Nicolas MASSART](https://github.com/NicolasMassart) for the pull request. - [#416] API: Added support for `@Command` annotation on methods (in addition to classes). Thanks to [illes](https://github.com/illes) for the pull request. - [#433] API: Added method `printHelpIfRequested` that accepts a `ColorScheme` parameter. Thanks to [Benny Bottema](https://github.com/bbottema) for the suggestion. - [#441] API: Added `hideParamSyntax` attribute to `@Option` and `@Parameters` to allow suppressing usage syntax decorations around the param label. Thanks to [Benny Bottema](https://github.com/bbottema) for the pull request. - [#22], [#415], [#436] API: Added internationalization and localization support via resource bundles. - [#473] Enhancement: Improved error messages for invalid input. - [#461] Bugfix: Script auto-completion only suggests options and never default bash completions. Thanks to [David Walluck](https://github.com/dwalluck) for the pull request. - [#466] Bugfix: Script auto-completion should not generate suggestions for options with arguments that have no known completions. Thanks to [David Walluck](https://github.com/dwalluck) for the pull request. - [#470] Bugfix: Script auto-completion should generate suggestions for short options with arguments. Thanks to [David Walluck](https://github.com/dwalluck) for the pull request. - [#444] Bugfix: Usage help shows duplicate aliases if registered with same alias multiple times. - [#452] Doc: Add UML class diagrams to picocli Javadoc. - [#475] Doc: Renamed module `examples` to `picocli-examples`. - [#478] Doc: Add convenience API example to `CommandLine` class Javadoc. ## Deprecations No features were deprecated in this release. ## Potential breaking changes The error message displayed on invalid input is different from previous releases. This may break unit tests that expect an exact error message. # Picocli 3.5.2 The picocli community is pleased to announce picocli 3.5.2. This is a bugfix release that fixes an issue where subcommand aliases were not recognized in some cases. This is the thirty-eighth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.5.2-new) * [Promoted features](#3.5.2-promoted) * [Fixed issues](#3.5.2-fixes) * [Deprecations](#3.5.2-deprecated) * [Potential breaking changes](#3.5.2-breaking-changes) ## New and Noteworthy ## Promoted Features Promoted features are features that were incubating in previous versions of picocli but are now supported and subject to backwards compatibility. No features have been promoted in this picocli release. ## Fixed issues - [#443] Bugfix: Subcommand aliases were not recognized in some cases. Thanks to [K. Alex Mills](https://github.com/kalexmills) for the bug report. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.5.1 The picocli community is pleased to announce picocli 3.5.1. This is a bugfix release that fixes an issue where CommandSpec injected into Mixins had a `null` CommandLine. This is the thirty-seventh public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.5.1-new) * [Promoted features](#3.5.1-promoted) * [Fixed issues](#3.5.1-fixes) * [Deprecations](#3.5.1-deprecated) * [Potential breaking changes](#3.5.1-breaking-changes) ## New and Noteworthy ## Promoted Features Promoted features are features that were incubating in previous versions of picocli but are now supported and subject to backwards compatibility. No features have been promoted in this picocli release. ## Fixed issues - [#439] Bugfix: CommandSpec injected into Mixins had a `null` CommandLine. Thanks to [Adam Zegelin](https://github.com/zegelin) for the bug report. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.5.0 The picocli community is pleased to announce picocli 3.5.0. This release contains new features, bugfixes and enhancements. Password support: for options and positional parameters marked as `interactive`, the user is prompted to enter a value on the console. When running on Java 6 or higher, picocli will use the Console.readPassword API so that user input is not echoed to the console. Client code can now perform simple validation in annotated setter methods by throwing a `ParameterException` on invalid input. Also, from this release, the comment character in @-files (argument files) and the end-of-options delimiter (`--` by default) are configurable. This is the thirty-sixth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.5.0-new) * [Promoted features](#3.5.0-promoted) * [Fixed issues](#3.5.0-fixes) * [Deprecations](#3.5.0-deprecated) * [Potential breaking changes](#3.5.0-breaking-changes) ## New and Noteworthy ### `Interactive` Options for Passwords or Passphrases This release introduces password support: for options and positional parameters marked as `interactive`, the user is prompted to enter a value on the console. When running on Java 6 or higher, picocli will use the Console.readPassword API so that user input is not echoed to the console. Example usage: ```java class Login implements Callable { @Option(names = {"-u", "--user"}, description = "User name") String user; @Option(names = {"-p", "--password"}, description = "Passphrase", interactive = true) String password; public Object call() throws Exception { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(password.getBytes()); System.out.printf("Hi %s, your passphrase is hashed to %s.%n", user, base64(md.digest())); return null; } private String base64(byte[] arr) { /* ... */ } } ``` When this command is invoked like this: ```java CommandLine.call(new Login(), "-u", "user123", "-p"); ``` Then the user will be prompted to enter a value: ``` Enter value for --password (Passphrase): ``` When running on Java 6 or higher, the user input is not echoed to the console. After the user enters a value and presses enter, the `call()` method is invoked, which prints the following: ```bash Hi user123, your passphrase is hashed to 75K3eLr+dx6JJFuJ7LwIpEpOFmwGZZkRiB84PURz6U8=. ``` ### Simple Validation in Setter Methods Methods annotated with `@Option` and `@Parameters` can do simple input validation by throwing a `ParameterException` when invalid values are specified on the command line. ```java class ValidationExample { private Map properties = new LinkedHashMap<>(); @Spec private CommandSpec spec; // injected by picocli @Option(names = {"-D", "--property"}, paramLabel = "KEY=VALUE") public void setProperty(Map map) { for (String key : map.keySet()) { String newValue = map.get(key); validateUnique(key, newValue); properties.put(key, newValue); } } private void validateUnique(String key, String newValue) { String existing = properties.get(key); if (existing != null && !existing.equals(newValue)) { throw new ParameterException(spec.commandLine(), String.format("Duplicate key '%s' for values '%s' and '%s'.", key, existing, newValue)); } } } ``` Prior to this release, the exception thrown from the method was wrapped in a `java.lang.reflect.InvocationTargetException`, which in turn was wrapped in a `PicocliException`, and finally in another `ParameterException`. By following the recipe above and throwing a `ParameterException` on invalid input, all these intermediate exceptions are skipped. ## Promoted Features Promoted features are features that were incubating in previous versions of picocli but are now supported and subject to backwards compatibility. No features have been promoted in this picocli release. ## Fixed issues - [#430] Bugfix: formatting was incorrect (did not break on embedded newlines) in the subcommands list descriptions. Thanks to [Benny Bottema](https://github.com/bbottema) for the bug report. - [#431] Better support for validation in setter methods: cleaner stack trace. - [#432] Make comment character in @-files (argument files) configurable. - [#359] Make end-of-options delimiter configurable. - [#82] Support reading passwords from the console with echoing disabled. ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.4.0 The picocli community is pleased to announce picocli 3.4.0. This release contains new features, bugfixes and enhancements. The parser can now ignore case when parsing arguments for an Enum option or positional parameter. New methods `Help.Ansi.text(String)` and `Help.Ansi.string(String)` assist client code in easily creating ANSI messages outside usage help and version help. This is the thirty-fifth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.4.0-new) * [Promoted features](#3.4.0-promoted) * [Fixed issues](#3.4.0-fixes) * [Deprecations](#3.4.0-deprecated) * [Potential breaking changes](#3.4.0-breaking-changes) ## New and Noteworthy ## Promoted Features Promoted features are features that were incubating in previous versions of picocli but are now supported and subject to backwards compatibility. No features have been promoted in this picocli release. ## Fixed issues - [#14] New API: Support enum values to be parsed in an case-insensitive way. - [#376] New API: `Help.Ansi.text(String)` and `Help.Ansi.string(String)` help client code easily create ANSI messages outside usage help and version help. - [#412] Enhancement: Enum constant names are now returned from `ArgSpec::completionCandidates()`. Thanks to [Radovan Panák](https://github.com/rpanak). - [#417] Enhancement: Ensure bash scripts have correct line separators. Thanks to [Holger Stenger](https://github.com/stengerh). - [#425] Enhancement: Fix autocomplete script errors in zsh. Thanks to [Anthony Keenan](https://github.com/anthonykeenan). - [#419] Bugfix: Default value for arrays was not rendered correctly with `@{DEFAULT-VALUE}`. - [#418] Doc: Improve installation instructions for autocompletion scripts. - [#420] Doc: Added a Quick Guide ## Deprecations No features were deprecated in this release. ## Potential breaking changes This release has no breaking changes. # Picocli 3.3.0 The picocli community is pleased to announce picocli 3.3.0. This release contains a bugfix for the JLine TAB completion support and improves the error messages for missing required parameters and unmatched arguments. This is the thirty-fourth public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.3.0-new) * [Promoted features](#3.3.0-promoted) * [Fixed issues](#3.3.0-fixes) * [Deprecations](#3.3.0-deprecated) * [Potential breaking changes](#3.3.0-breaking-changes) ## New and Noteworthy ### `UnmatchedArgumentException` Improvements The `UnmatchedArgumentException` class now has several methods that allow an application to offer suggestions for fixes to the end user. For example: ```java class App { @Option(names = "--file") File[] files; @Option(names = "--find") String pattern; public static void main(String[] args) { App app = new App(); try { new CommandLine(app).parse(args); // ... } catch (ParameterException ex) { System.err.println(ex.getMessage()); if (!UnmatchedArgumentException.printSuggestions(ex, System.err)) { // new API ex.getCommandLine().usage(System.err, ansi); } } } } ``` If you run this class with an invalid option that is similar to an actual option, the `UnmatchedArgumentException.printSuggestions` method will show the actual options. For example: ``` -fi ``` Prints this output: ``` Unknown option: -fi Possible solutions: --file, --find ``` This is the behaviour for the `CommandLine` convenience methods `run`, `call` and `parseWithHandlers`. Note that if possible fixes are found, the usage help message is not displayed. ## Promoted Features Promoted features are features that were incubating in previous versions of picocli but are now supported and subject to backwards compatibility. No features have been promoted in this picocli release. ## Fixed issues - [#411] Bugfix: Completion candidates were only generated for the first option, not for subsequent options. - [#409] Enhancement: Improve error message for missing required positional parameters. Thanks to [Mārtiņš Kalvāns](https://github.com/sisidra) and [Olle Lundberg](https://github.com/lndbrg). - [#298] Enhancement: Add help for mistyped commands and options. Added new API to `UnmatchedArgumentException`. Thanks to [Philippe Charles](https://github.com/charphi). ## Deprecations No features were deprecated in this release. ## Potential breaking changes The error message format has changed. This may impact client tests that expect a specific error message. # Picocli 3.2.0 The picocli community is pleased to announce picocli 3.2.0. This release contains new features and enhancements: * Improved support for Dependency Injection * Methods can now be annotated with `@Option` and `@Parameters` * Support for JLine-based interactive command line interfaces (`completionCandidates` attribute on `@Option` and `@Parameters`, and the `AutoComplete.complete` method) * New `@Spec` annotation for injecting a command with its `CommandSpec` This is the thirty-third public release. Picocli follows [semantic versioning](http://semver.org/). ## Table of Contents * [New and noteworthy](#3.2.0-new) * [Promoted features](#3.2.0-promoted) * [Fixed issues](#3.2.0-fixes) * [Deprecations](#3.2.0-deprecated) * [Potential breaking changes](#3.2.0-breaking-changes) ## New and Noteworthy ### Dependency Injection This release makes integration with Dependency Injection containers extremely easy: * `CommandLine` constructor now accepts a `Class` instance as the user object, and will delegate to the `IFactory` to get an instance. * New `CommandLine.run(Class, IFactory, ...)` and `CommandLine.call(Class, IFactory, ...)` methods. These work the same as the existing `run` and `call` methods except that the `Runnable` or `Callable` instance is created by the factory. The below example shows how to create an `IFactory` implementation with a Guice `Injector`: ```java import com.google.inject.*; import picocli.CommandLine.IFactory; public class GuiceFactory implements IFactory { private final Injector injector = Guice.createInjector(new DemoModule()); @Override public K create(Class aClass) throws Exception { return injector.getInstance(aClass); } static class DemoModule extends AbstractModule { @Override protected void configure() { bind(java.util.List.class).to(java.util.LinkedList.class); bind(Runnable.class).to(InjectionDemo.class); } } } ``` Use the custom factory when creating a `CommandLine` instance, or when invoking the `run` or `call` convenience methods: ```java import javax.inject.Inject; @Command(name = "di-demo") public class InjectionDemo implements Runnable { @Inject java.util.List list; @Option(names = "-x") int x; public static void main(String[] args) { CommandLine.run(Runnable.class, new GuiceFactory(), args); } @Override public void run() { assert list instanceof java.util.LinkedList; } } ``` ### Annotated Methods From this release, `@Option` and `@Parameter` annotations can be added to methods as well as fields of a class. For concrete classes, annotate "setter" methods (methods that accept a parameter) and when the option is specified on the command line, picocli will invoke the method with the value specified on the command line, converted to the type of the method parameter. Alternatively, you may annotate "getter-like" methods (methods that return a value) on an interface, and picocli will create an instance of the interface that returns the values specified on the command line, converted to the method return type. This feature is inspired by [Jewel CLI](https://github.com/lexicalscope/jewelcli). #### Annotating Methods of an Interface The `@Option` and `@Parameters` annotations can be used on methods of an interface that return a value. For example: ```java interface Counter { @Option(names = "--count") int getCount(); } ``` You use it by specifying the class of the interface: ```java CommandLine cmd = new CommandLine(Counter.class); // specify a class String[] args = new String[] {"--count", "3"}; cmd.parse(args); Counter counter = cmd.getCommand(); // picocli created an instance assert counter.getCount() == 3; // method returns command line value ``` #### Annotating Methods of a Concrete Class The `@Option` and `@Parameters` annotations can be used on methods of a class that accept a parameter. For example: ```java class Counter { int count; @Option(names = "--count") void setCount(int count) { this.count = count; } } ``` You use it by passing an instance of the class: ```java Counter counter = new Counter(); // the instance to populate CommandLine cmd = new CommandLine(counter); String[] args = new String[] {"--count", "3"}; cmd.parse(args); assert counter.count == 3; // method was invoked with command line value ``` ### JLine Tab-Completion Support This release adds support for JLine Tab-Completion. [Jline 2.x](https://github.com/jline/jline2) and [3.x](https://github.com/jline/jline3) is a Java library for handling console input, often used to create interactive shell applications. Command line applications based on picocli can generate completion candidates for the command line in the JLine shell. The generated completion candidates are context sensitive, so once a subcommand is specified, only the options for that subcommand are shown, and once an option is specified, only parameters for that option are shown. Below is an example picocli `Completer` implementation for JLine 2.x: ```java import jline.console.completer.ArgumentCompleter; import jline.console.completer.Completer; import picocli.AutoComplete; import picocli.CommandLine; import picocli.CommandLine.Model.CommandSpec; import java.util.List; public class PicocliJLineCompleter implements Completer { private final CommandSpec spec; public PicocliJLineCompleter(CommandSpec spec) { this.spec = spec; } @Override public int complete(String buffer, int cursor, List candidates) { // use the jline internal parser to split the line into tokens ArgumentCompleter.ArgumentList list = new ArgumentCompleter.WhitespaceArgumentDelimiter().delimit(buffer, cursor); // let picocli generate completion candidates for the token where the cursor is at return AutoComplete.complete(spec, list.getArguments(), list.getCursorArgumentIndex(), list.getArgumentPosition(), cursor, candidates); } } ``` ### Completion Candidates From this release, `@Options` and `@Parameters` have a new `completionCandidates` attribute that can be used to generate a list of completions for this option or positional parameter. For example: ```java static class MyAbcCandidates extends ArrayList { MyAbcCandidates() { super(Arrays.asList("A", "B", "C")); } } class ValidValuesDemo { @Option(names = "-o", completionCandidates = MyAbcCandidates.class) String option; } ``` This will generate completion option values `A`, `B` and `C` in the generated bash auto-completion script and in JLine. ### `${DEFAULT-VALUE}` Variable From picocli 3.2, it is possible to embed the default values in the description for an option or positional parameter by specifying the variable `${DEFAULT-VALUE}` in the description text. Picocli uses reflection to get the default values from the annotated fields. The variable is replaced with the default value regardless of the `@Command(showDefaultValues)` attribute and regardless of the `@Option(showDefaultValues)` or `@Parameters(showDefaultValues)` attribute. ```java class DefaultValues { @Option(names = {"-f", "--file"}, description = "the file to use (default: ${DEFAULT-VALUE})") File file = new File("config.xml"); } CommandLine.usage(new DefaultValues(), System.out); ``` This produces the following usage help: ```text Usage:
-f= -f, --file= the file to use (default: config.xml) ``` ### `${COMPLETION-CANDIDATES}` Variable Similarly, it is possible to embed the completion candidates in the description for an option or positional parameter by specifying the variable `${COMPLETION-CANDIDATES}` in the description text. This works for java `enum` classes and for options or positional parameters of non-enum types for which completion candidates are specified. ```java enum Lang { java, groovy, kotlin, javascript, frege, clojure } static class MyAbcCandidates extends ArrayList { MyAbcCandidates() { super(Arrays.asList("A", "B", "C")); } } class ValidValuesDemo { @Option(names = "-l", description = "Enum. Values: ${COMPLETION-CANDIDATES}") Lang lang = null; @Option(names = "-o", completionCandidates = MyAbcCandidates.class, description = "Candidates: ${COMPLETION-CANDIDATES}") String option; } CommandLine.usage(new ValidValuesDemo(), System.out); ``` This produces the following usage help: ```text Usage:
-l= -o=