JewelCLI is a Java library for command-line parsing that yields clean code. It uses Proxied Interfaces Configured with Annotations to dynamically build a type-safe API for your command-line parameters.
An example parameter interface Person.java
:
import uk.co.flamingpenguin.jewel.cli.Option;
public interface Person {
@Option String getName();
@Option int getTimes();
}
An example usage of the parameter interface Hello.java
:
import static uk.co.flamingpenguin.jewel.cli.CliFactory.parseArguments;
import uk.co.flamingpenguin.jewel.cli.ArgumentValidationException;
public class Hello {
public static void main(String [] args) {
try {
Person person = parseArguments(Person.class, args);
for (int i = 0; i < person.getTimes(); i++)
System.out.println("Hello " + person.getName());
} catch(ArgumentValidationException e) {
System.err.println(e.getMessage());
}
}
}
Save copies of the files above to a single directory and download the JewelCLI 0.6 JAR to that directory as well.
Compile and run the example in Bash on Linux/Mac OS X/etc.:
javac -cp jewelcli-0.6.jar:. Person.java Hello.java
java -cp jewelcli-0.6.jar:. Hello --name="John Doe" --times=3
Compile and run the example in the Windows Command Prompt:
javac -cp jewelcli-0.6.jar;. Person.java Hello.java
java -cp jewelcli-0.6.jar;. Hello --name="John Doe" --times=3
Running the example should yield the following output:
Hello John Doe
Hello John Doe
Hello John Doe