Because sometimes making a CLI can be a real pain in the a$$
- combine some libraries that work: argparse4j, jansi, cli-progress
- easily make a CLI app that is extensible
- remove some boilerplate code
This library uses Java's ServiceLoader to gather up all the CliCommands in the application's classpath. This makes it really easy for anyone to add a new command they "wish" they had in your application.
I would suggest checking out the example
module. This is an example of how to setup an application with maven.
Base requirements
- Make the
cli.pi.CliApp
yourMain-Class
in yourMANIFEST.MF
so your commands will be picked up and exceptions will be handled - Create file
app-info.properties
in the root directory of your application. This file expects to have one propertyapp.version
and this is used when a user wants to know the version of our application. - All your commands are expected to extend the class
CliCommand
and to have an entry of each command class in theMETA-INF/services/cli.pi.command.CliCommand
file. This can be auto-generated for you if you look in the FAQ.
- Is there anyway to auto-generate the files that get put in
META-INF/services
for myCliCommand
s ?- I usually annotate my
CliCommand
implementations with the@MetaInfServices
annotation provided in themetainf-services
module. This module contains an annotation processor that will generate the service file at compile time based on whatservice
you declared in the annotation. So you only need this module at compile time and not runtime.
- I usually annotate my