Search code examples
javapicocli

Picocli: How can one handle no arguments and options scenario


I am using the picocli java command line library to implement a command line application. However I would like to know whether picocli offers a feature that can help handle the situation where the command line does not receive any arguments or options something default case.

Thank you


Solution

  • I'm not sure if this answers your question, but it is certainly possible to create a picocli-based command that has no options or positional parameters:

    @Command(name = "demo", description = "no options or positional parameters")
    public class Demo implements Runnable {
    
        @Override
        void run() {
            System.out.println("Hello");
        }
    
        public static void main(String[] args) {
            CommandLine.run(new Demo(), args);
        }
    }
    

    Or is your question about how options can be given default values? If that is the case, can you take a look at the Default Values section of the user manual and let us know what is unclear?