Questions tagged [picocli]

Picocli is a command line parsing library for Java and other JVM languages. Distinguishing features: provides both a programmatic and an annotation API, usage help with ANSI colors, autocompletion on supported platforms and strong support for nested subcommands. Designed to optionally be included as source to avoid adding dependencies.

Picocli is an open-source library for creating command line applications in Java and other JVM languages with a minimum amount of code. Distinguishing features: provides both a programmatic and an annotation API, usage help with ANSI colors, autocompletion on supported platforms, nested subcommands (to any depth) and strongly typed options as well as positional parameters. Designed to optionally be included as source to avoid adding dependencies.

How to ask

If you are using or considering Picocli and your question is related to it, then you should add this tag. You should explain what you intend to achieve, how you tried to achieve it, what the actual behavior was and how that is different from your expectations.

Picocli Reference Documentation

Useful links

136 questions
1
vote
1 answer

How to get PicoCLI to interpret next item as flag and not string

I'm having a problem trying to get the PicoCLI library in Java to interpret the next position after a certain flag to be a string, and not another flag. Say for example I have the following command: $ my-cli -t -b -b "some value" my-file.txt What I…
Scott Crooks
  • 1,523
  • 4
  • 24
  • 39
1
vote
1 answer

PicoCLI "defaultValue" and option values for primitive arrays

How are default values and option values for primitive arrays properly specified in PicoCli? A primitive value can be annotated with a defaultValue string value: @Option( names = {"--one-value"}, defaultValue = "1.25", description…
Jan Nielsen
  • 10,892
  • 14
  • 65
  • 119
1
vote
0 answers

Picocli: is it possible to calculate Option default value with help of some other Autowired field?

I want to implement the following logic of Option default value calculation @Command(name = "test-command") public class TestCommand implements Callable { @Autowired DefaultValueUtils utils; @ArgGroup EntityGroup functions…
olly2334
  • 11
  • 2
1
vote
1 answer

Successfully built Picocli project with GraaVM native image but can't run it

I've been trying to get a hello world project working for a Picocli/GraalVM project. I'm on an M1 Mac running Montery, Java 11, and GraalVM 22.3. I followed he Picocli documentation, but get "unmatched argument" errors when trying to run the native…
1
vote
1 answer

Picocli Groovy script error Annotation @picocli.CommandLine$Option is not allowed on element LOCAL_VARIABLE

I am trying in a groovy script to use picocli to get an interactive password prompt and get the error @picocli.CommandLine$Option is not allowed on element LOCAL_VARIABLE. I am using Groovy 4.0.5 and Picocli 4.6.3. Below is my code. import static…
Withnoe
  • 115
  • 1
  • 9
1
vote
1 answer

Java: picocli: How to provide argument to command without naming it?

Is it possible to provide argument to @CommandLine.Command without explicitly naming the argument in picocli? As example the following command can be invoked as: open n 1. However, I would like to be able to invoke the command as open…
user7858768
  • 838
  • 7
  • 22
1
vote
1 answer

Possible side effects when several CommandLine instance "work" on the same instance of an annotated class?

picoCLI's @-file mechanism is almost what I need, but not exactly. The reason is that I want to control the exact location of additional files parsed -- depending on previous option values. Example: When called with the options srcfolder=/a/b…
LTB
  • 31
  • 3
1
vote
1 answer

Can I define custom descriptions for Mixins for separate uses with picocli?

I have an algorithm with many similar @Options, for instance: @Option(names = {"-if", "--input-file"}, required = true, description = "description") public void setInputFilePath(String value) throws FileNotFoundException { …
1
vote
2 answers

How can I construct the help functionality to divide subcommands into groups with separate descriptive headers?

A tool I am currently working on has a lot of subcommands which makes picocli's help output unclear. My code looks like this: @Command(name = "toolName", version = "version", sortOptions = false, parameterListHeading =…
1
vote
1 answer

picocli combine help message grouping and a required argument

I would like to group options in the help message but have one option in that group required. Actually, I want to have one subgroup of the help-message-group required, but I have trouble with both: import java.util.concurrent.Callable; import…
1
vote
1 answer

In picocli how do you make options on the command line to override the same option in an @-file

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…
1
vote
1 answer

arggroup with default value in picocli

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…
kien bui
  • 1,760
  • 2
  • 17
  • 33
1
vote
1 answer

Bridging CLI argument parsing with application setup

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…
Jan Nielsen
  • 10,892
  • 14
  • 65
  • 119
1
vote
3 answers

How to decide Quarkus application arguments in Kubernetes at run-time?

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…
1
vote
1 answer

How to bundle an executable jar file to be run as a cli command on macOS with jpackage (or similar tools)?

I have written a command line tool using picocli and Kotlin. Then I compiled it to an executable uber jar and it actually works as a standalone application by running java -jar MyJarFile.jar [cli options and parameters] But how do I bundle it so…
Essay97
  • 648
  • 1
  • 9
  • 24