picocli, a powerful framework for building command line applications

picocli

Picocli the framework for creating cli apps

If you are starting out in the world of programming and you have already gotten a little into Java, let me tell you that surfing the net I have found an excellent tool that in my student days I would have liked to know, since this tool that we will talk about today is positioned as a framework for the creation of command line applications.

The tool we will talk about is Picocli, which is intended to be the easiest way to use to create rich command line applications that can be executed inside and outside the JVM.

Although it is not necessary to explain a bit about what the command line interface is, for those readers who have not fully delved into programming or even for those who have only done it self-taught and are still unaware of several terms, I can tell you that the command line or better known as CLI, is a type of user interface that allows users to give instructions to a program through a simple text line (something we do every day in Linux).

CLIs can be used interactively, by writing instructions to some kind of text input, or they can be used in a much more automated way (batch), by reading commands from a script file.

This is where Picocli comes in, which is a library and a Framework written in Java, containing an annotation API and a programmatic API.

Of the picocli characteristics, it is highlighted that:

  • It has help of use with colors and ANSI styles
  • Autocomplete TAB
  • Nested subcommands.
  • Supports git-like subcommands and any option prefix styles
  • Allows POSIX-style grouped short options
  • Custom type converters
  • password options
  • Picocli applications can be compiled into a single file
  • Be very compact with no boilerplate code
  • It comes with an annotation processor that activates Graal
  • Support for deniable options
  • Advanced Quoted Values ​​and Argument Groups
  • Makes it easy to follow command line interface guidelines.
  • And more

The interesting thing about Picocli is which, as already mentioned in its characteristics, is that offers a way to allow users to run picocli-based applications without requiring the picocli library as an external dependency: all the source code lives in a single file.

It is mentioned that:

Picocli-based applications can be compiled ahead of time into a native image, with extremely fast startup time and lower memory requirements.

As picocli works, it initializes the class from the command line arguments, converting the input to strongly typed data.

Picocli distinguishes between named options and positional parameters and allows both to be strongly typed. Multi-value fields can specify an exact number of parameters or a range (eg, 0..*, 1..2).

It supports map options such as -Dkey1=val1 -Dkey2=val2, where both the key and the value can be safely written. Analyzer trace makes it easy to troubleshoot. Command line argument files (@-files) allow applications to handle very long command lines.

It should be noted that picocli's autocompletion only works in some shells such as Bash or Zsh, since not all of them support this function.

Finally if you are interested in knowing more about it, you can check the details In the following link.

How to implement picocli?

For those interested in being able to implement picocli in their project or start a new project with picocli, they can do so by downloading the latest version of picocli from the following link.

And the implementation can be done as the case may be, for example in Maven

<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.7.4</version>
</dependency>

scale sbt

libraryDependencies += "info.picocli" % "picocli" % "4.7.4"

Ivy

<dependency org="info.picocli" name="picocli" rev="4.7.4" />

Grape

@Grapes(
@Grab(group='info.picocli', module='picocli', version='4.7.4')
)

leiningen

[info.picocli/picocli "4.7.4"]

Builder

'info.picocli:picocli:jar:4.7.4'

jbang

//DEPS info.picocli:picocli:4.7.4

The documentation, as well as all its information, can be consulted from the following link.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.