I'm trying to build a CLI in Java using PICOCLI and I'm STUCK at a very basic point. I simply cannot get my application to consumer an option and it's value. Here's my class:
package com.example.demo;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import picocli.CommandLine;
@SpringBootApplication
@CommandLine.Command(name = "Greet", header = "%n@|green Hello world demo|@")
class DemoApplication implements Runnable {
@CommandLine.Option(names = {"-u", "--user"}, required = true, description = "The user name.")
String userName;
public void run() {
System.out.println("Hello, " + userName);
}
public static void main(String... args) {
CommandLine.run(new DemoApplication(), System.err, args);
}
}
I then do a mvn package
, cd target
and java -jar demo-1.0.jar Greet -u pico
but I'm only met with this:
Unmatched argument at index 0: 'Greet'
Hello world demo
Usage: Greet -u=<userName>
-u, --user=<userName> The user name.
I have run out of patience trying to print a simple message ! I do not know how else to solve this. Please help!