picocli | Picocli is a modern framework for building powerful, user-friendly, GraalVM-enabled command line app | Parser library

 by   remkop Java Version: 4.7.5 License: Apache-2.0

kandi X-RAY | picocli Summary

kandi X-RAY | picocli Summary

picocli is a Java library typically used in Utilities, Parser applications. picocli has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can download it from GitHub, Maven.

Picocli aims to be the easiest-to-use way to create rich command line applications that can run on and off the JVM. Considering picocli? Check what happy users say about picocli. Picocli is a modern library and framework, written in Java, that contains both an annotations API and a programmatic API. It features usage help with ANSI colors and styles, TAB autocompletion 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. Picocli-based applications can be ahead-of-time compiled to a native image, with extremely fast startup time and lower memory requirements, which can be distributed as a single executable file. Picocli comes with an annotation processor that automatically Graal-enables your jar during compilation. Picocli applications can be very compact with no boilerplate code: your command (or subcommand) can be executed with a single line of code. Simply implement Runnable or Callable, or put the business logic of your command in a @Command-annotated method. Picocli makes it easy to follow Command Line Interface Guidelines. 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 (and nested sub-subcommands), any option prefix style, POSIX-style grouped short options, custom type converters, password options and more. Picocli distinguishes between named options and positional parameters and allows both to be strongly typed. Multi-valued fields can specify an exact number of parameters or a range (e.g., 0..*, 1..2). Supports Map options like -Dkey1=val1 -Dkey2=val2, where both key and value can be strongly typed. Parser tracing facilitates troubleshooting. Command-line argument files (@-files) allow applications to handle very long command lines. Generates polished and easily tailored usage help and version help, using ANSI colors where possible. Requires at minimum Java 5, but is designed to facilitate the use of Java 8 lambdas. Tested on all Java versions between 5 and 18-ea (inclusive). Picocli-based command line applications can have TAB autocompletion, interactively showing users what options and subcommands are available. When an option has completionCandidates 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 and picocli-shell-jline3 modules with JLine Completer implementations for building interactive shell applications. Unique features in picocli include support for negatable options, advanced quoted values, and argument groups. Argument groups can be used to create mutually exclusive options, mutually dependent options, option sections in the usage help message and repeating composite arguments like ([-a= -b= -c=] (-x | -y | -z)).... For advanced use cases, applications can access the picocli command object model with the @Spec annotation, and implement custom parameter processing for option parameters if the built-in logic is insufficient. Picocli-based applications can easily integrate with Dependency Injection containers. The Micronaut microservices framework has built-in support for picocli. Picocli ships with a picocli-spring-boot-starter module that includes a PicocliSpringFactory and Spring Boot auto-configuration to use Spring dependency injection in your picocli command line application. The user manual has examples of integrating with Guice, Spring Boot, Micronaut, Quarkus and with containers that comply to CDI 2.0 specification (JSR 365).
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              picocli has a highly active ecosystem.
              It has 4278 star(s) with 386 fork(s). There are 46 watchers for this library.
              There were 2 major release(s) in the last 12 months.
              There are 103 open issues and 1318 have been closed. On average issues are closed in 38 days. There are 9 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of picocli is 4.7.5

            kandi-Quality Quality

              picocli has 0 bugs and 0 code smells.

            kandi-Security Security

              picocli has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              picocli code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              picocli is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              picocli releases are available to install and integrate.
              Deployable package is available in Maven.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              picocli saves you 283359 person hours of effort in developing the same functionality from scratch.
              It has 276796 lines of code, 6056 functions and 720 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed picocli and discovered the below as its top functions. This is intended to give you an instant insight into picocli implemented functionality, and help decide if they suit your requirements.
            • This method applies a value to a single valued field .
            • Generate a function for the given command and command line .
            • Executes user object
            • Create the custom usage help factory .
            • Generates the options .
            • Modify base script type .
            • Build options and positions from method parameters .
            • Create the synopsis text for the options .
            • Split a string into chunks .
            • Returns an array of textual descriptions for the given option .
            Get all kandi verified functions for this library.

            picocli Key Features

            No Key Features are available at this moment for picocli.

            picocli Examples and Code Snippets

            arggroup with default value in picocli
            Javadot img1Lines of Code : 64dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            @Command
            public class CMD implements Runnable {
            
                @Parameters
                private String x;
                
                @ArgGroup(exclusive = false)
                private Group group = new Group();
            
                static class Group {
                    @Option(names = "-a", required = true, de
            copy iconCopy
            import picocli.CommandLine.PropertiesDefaultProvider;
            
            @Command(name = "myapp", defaultValueProvider = PropertiesDefaultProvider.class)
            class MyApp { }
            
            class MyApp { 
                @Option(names = "-D")
                void setSystemPro
            Parsing picocli-based CLI usage output into structured data
            Javadot img3Lines of Code : 34dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            @Command(name = "taker-mvo-2", mixinStandardHelpOptions = true, version = "taker-mvo-2 0.2")
            class TakerMvo2 implements Runnable {
                // ...
            
                @Option(names = {"-C", "--credential"}, description = "credential file")
                File file;
            
               
            PicoCLI: Dependent and Exclusive Arguments mixed
            Javadot img4Lines of Code : 54dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            Usage: app [-hV] [-A [-B]]
                   app [-hV] [-A [-A1] [-A2] [-A3]]
            
            import picocli.CommandLine;
            import picocli.CommandLine.*;
            import picocli.CommandLine.Model.CommandSpec;
            
            @Command(name = "app", mixinStandardHelpOp
            CLI with Picocli: Call main command before sub command get called
            Javadot img5Lines of Code : 59dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            CommandLine.run(callable, args); // internally uses RunLast, equivalent to: 
            new CommandLine(callable).parseWithHandler(new RunLast(), args);
            
            public static void main(String[] args) {
                args = new String[] { "--ve
            How to print subcommand result automatically?
            Lines of Code : 121dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                @CommandLine.Command
                public String sayGoodbye()
                {
                    return printValue("GoodBye");
                }
            
            // extend RunLast to handle requests for help/version and exit code stuff
            class PrintingExecutionStrategy ex
            How to improve command performance at runtime?
            Lines of Code : 93dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            Index: jsoar-core/src/main/java/org/jsoar/kernel/commands/LogCommand.java
            IDEA additional info:
            Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
            <+>UTF-8
            ===================================================================
            --
            Non-zero exit code on missing parameter with picocli
            Lines of Code : 36dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            @Command
            class ExitCodeDemo implements Callable {
                @Parameters(index = "0", description = "manifest")
                private File manifest;
            
                public Integer call() {
                    // business logic here
                    return ok ? 0 : 123;
                }
            
                public 

            Community Discussions

            QUESTION

            How can I construct the help functionality to divide subcommands into groups with separate descriptive headers?
            Asked 2022-Apr-08 at 12:48

            A tool I am currently working on has a lot of subcommands which makes picocli's help output unclear. My code looks like this:

            ...

            ANSWER

            Answered 2022-Apr-08 at 02:49

            Yes that is possible by diving under the hood of picocli's Help API.

            One idea is to have a custom IHelpSectionRenderer, see this example: https://github.com/remkop/picocli/blob/main/picocli-examples/src/main/java/picocli/examples/customhelp/GroupingDemo.java

            Source https://stackoverflow.com/questions/71778823

            QUESTION

            Micronaut application built with Launch4J not launching
            Asked 2022-Mar-30 at 13:25

            I have successfully ported my desktop application from Dagger/Spring to Micronaut/Spring (there's just way too much Spring code in there for me to be able strip it all out in a timely manner). Using Micronaut and PicoCLI everything is working beautifully in Eclipse/Gradle. It's launching, tests are passing, so now I want to do a build and install it to make sure that everything will work for our customer.

            Our build (via Gradle) uses Shadow (com.github.johnrengelman.shadow) to combine our application with all of its dependencies into a single Jar file. I've checked and all expected dependencies appear to be present, and from the look of it the generated Micronaut classes are also present in the shadow jar. We then use Launch4J to make this shadow jar executable. From everything that I can tell, the output from Launch4J looks to be correct, however when I try to run the installed application, the splash screen appears for a fraction of a second and that's it. When I run the Launch4J generated executable as a jar file, I get the following:

            ...

            ANSWER

            Answered 2022-Mar-30 at 13:25

            I haven't been able to find any information for using launch4j with more than 65535 files (i.e.: something like the shadowJar zip64 flag), nor really much of any information in this regard in general for that matter. However one solution that works for me, is to set dontWrapJar to true. This creates a tiny launcher for running the created jar file with the bundled JRE, rather than converting the entire jar, keeping all (or at least the majority of) the files out of the launch4j generated executable. The updated gradle task is as follows

            Source https://stackoverflow.com/questions/71593058

            QUESTION

            arggroup with default value in picocli
            Asked 2022-Mar-16 at 05:55

            Write cmd interface with Java code used picocli v4.6.3

            My case: ./cmd [-a -b [-c]]

            user put a,b option or got default value example:

            • user only put: ./cmd x1

              a,b,c option got default value

            • ./cmd x1 -a=a1

              request input b option and vice versa (c option still get default value)

            • ./cmd x1 -c=c1

              a & b option get default value

            ...

            ANSWER

            Answered 2022-Mar-16 at 05:55

            Original Answer

            The picocli user manual has a detailed section on assigning default values in argument groups.

            Applications need to do both of the below:

            • specify default values in both the @Option annotation, and in the initial value of the @Option-annotated field. (Yes, that means some duplication.)
            • manually instantiate the @ArgGroup-annotated field

            For your example, that means:

            Source https://stackoverflow.com/questions/71419975

            QUESTION

            In picocli how do you make options on the command line to override the same option in an @-file
            Asked 2022-Mar-16 at 04:59

            I'm currently using picocli 4.7.0-SNAPSHOT to great effect in a Java 11 application that has a complex set of options, so I am making use of the @-file functionality.

            What I am trying to get to work is an option specified directly on the command line to override the same option if it exists in the @-file. So options specified on the command line take precedence over the @-file. Is that possible.

            When I try to run my test application, heavily based on the picocli example, with both a command line option and an @-file, I get the following error from picocli along with the expected usage:

            ...

            ANSWER

            Answered 2022-Mar-16 at 04:59

            Let me paraphrase the question to see if I understand it correctly:

            If the end user specifies an option directly on the command line, the command line value should be used, while if that option is not specified on the command line, the value in a file should be used.

            Essentially, you are using an @-file with the intention to define default values for one or more options. However, that is not what @-files were designed for: picocli cannot distinguish between arguments that came from the command line and arguments that came from the @-file.

            I would suggest using picocli's default provider mechanism instead.

            One idea is to use the built-in PropertiesDefaultProvider:

            Source https://stackoverflow.com/questions/71479785

            QUESTION

            Bridging CLI argument parsing with application setup
            Asked 2022-Feb-22 at 02:16

            My PicoCLI-based application has multiple commands and sub-commands with general options that apply to all commands, and some options which apply to the specific command. The general options are used for all the commands.

            My PicoCLI (sub-)commands are similar to this example:

            ...

            ANSWER

            Answered 2022-Feb-22 at 02:16

            One idea is to use a custom Execution Strategy.

            The Initialization Before Execution section of the picocli user manual has an example. Let's try to modify that example for your use case. I arrive at something like this:

            Source https://stackoverflow.com/questions/71204021

            QUESTION

            How to decide Quarkus application arguments in Kubernetes at run-time?
            Asked 2022-Feb-21 at 20:35

            I've built a Quarkus 2.7.1 console application using picocli that includes several subcommands. I'd like to be able to run this application within a Kubernetes cluster and decide its arguments at run-time. This is so that I can use the same container image to run the application in different modes within the cluster.

            To get things started I added the JIB extension and tried setting the arguments using a configuration value quarkus.jib.jvm-arguments. Unfortunately it seems like this configuration value is locked at build-time so I'm unable to update this at run-time.

            Next I tried setting quarkus.args while using default settings for JIB. The configuration value documentation makes it sound general enough for the job but it doesn't seem to have an affect when the application is run in the container. Since most references to this configuration value in documentation are in the context of Dev Mode I'm wondering if this may be disabled outside of that.

            How can I get this application running in a container image with its arguments decided at run-time?

            ...

            ANSWER

            Answered 2022-Feb-16 at 16:11

            I was able to find a solution to the problem with a bit of experimenting this morning.

            With the quarkus-container-image-docker extension (instead of quarkus.jib.jvm-arguments) I was able to take the template Dockerfile.jvm and extend it to pass through arguments to the CLI. The only line that needed changing was the ENTRYPOINT (details included in the snippet below). I changed the ENTRYPOINT form (from exec to shell) and added an environment variable as an argument to pass-through program arguments.

            Source https://stackoverflow.com/questions/71118896

            QUESTION

            How do I transfer my parsed array data from one class to another?
            Asked 2022-Feb-21 at 17:03

            My program uses Picocli to parse XML data and store it in an ArrayList. For some reason, the information gets removed when I try to access it from another class.

            I run the code below, and it shows the elements just fine:

            ...

            ANSWER

            Answered 2022-Feb-21 at 13:51

            The static context of the SourceSentences.main() is lost once you run the getArrayElements.main() method. The parsing of your XML data never happened as far as getArrayElements.main() was concerned.

            You need to call the translate method from inside the getArrayElements' main function.

            Source https://stackoverflow.com/questions/70819977

            QUESTION

            Should EntityManagerFactory be closed at application shutdown?
            Asked 2022-Feb-14 at 11:37

            I have a Java application that has a GUI made with Swing and that uses two databases interchangeably. One of the two databases is mongoDB and the other one is MySQL. Which database to use is chosen with a command line option. For the MySQL database I am also using Hibernate and JPA. The code I have looks like this:

            ...

            ANSWER

            Answered 2022-Feb-14 at 11:37

            Short answer, yes, it should be closed. And the reason can be found at this answer:

            The JVM will release all active resources upon termination; however, this does not ensure that the other end will free the resource too, so explicitly closing resources is in every programmer's best interest.

            So in my case, it is true that the EntityManager and factory are closed at application shutdown, but this does not ensure that they are properly dealt with on the other end. I didn't mention it in my question, but in fact the same thing holds true for the Mongo Client as well (see this answer):

            If you ever re-deploy your web application without first restarting your application server, you must ensure that the MongoClient is closed when your web application is shutdown.

            About the implementation I made an interface that I called DBInitializer. I instantiated an object of type MongoInitializer or MySQLInitializer (both implementing DBInitializer) inside the main method. See code for more clarity.

            DBInitializer:

            Source https://stackoverflow.com/questions/71084515

            QUESTION

            Groovy 4, JDK 11: Caught: Assertion failed
            Asked 2022-Feb-10 at 02:28

            I mimic code snippet at reference document at https://groovy-lang.org/syntax.html#_groovydoc_comment

            Program

            ...

            ANSWER

            Answered 2022-Feb-10 at 02:28

            QUESTION

            How to get ApplicationContext in Micronaut CLI application into Httpclient class?
            Asked 2022-Feb-07 at 21:08

            I am running a Micronaut CLI application via Picocli runner wanted to use applicationContext for injecting/getting the bean during application execution.

            ...

            ANSWER

            Answered 2022-Feb-07 at 21:08

            The property needs to be in the AuthenticationFilter class. That class should be annotated with jakarta.inject.Singleton and should not be private

            Source https://stackoverflow.com/questions/70950655

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install picocli

            You can add picocli as an external dependency to your project, or you can include it as source. See the source code. Copy and paste it into a file called CommandLine.java, add it to your project, and enjoy!.

            Support

            4.x User manual: https://picocli.info4.x Quick Guide4.x API JavadocCommand line autocompletionProgrammatic APIFAQGraalVM AOT Compilation to Native Image
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
            Maven
            Gradle
            CLONE
          • HTTPS

            https://github.com/remkop/picocli.git

          • CLI

            gh repo clone remkop/picocli

          • sshUrl

            git@github.com:remkop/picocli.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link