born2snipe / cli-pi

A simple little framework for making Java CLI applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cli-Pi

Because sometimes making a CLI can be a real pain in the a$$

What does it do?

  • combine some libraries that work: argparse4j, jansi, cli-progress
  • easily make a CLI app that is extensible
  • remove some boilerplate code

How does it work?

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.

How do I get started?

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 your Main-Class in your MANIFEST.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 property app.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 the META-INF/services/cli.pi.command.CliCommand file. This can be auto-generated for you if you look in the FAQ.

FAQ

  • Is there anyway to auto-generate the files that get put in META-INF/services for my CliCommands ?
    • I usually annotate my CliCommand implementations with the @MetaInfServices annotation provided in the metainf-services module. This module contains an annotation processor that will generate the service file at compile time based on what service you declared in the annotation. So you only need this module at compile time and not runtime.

About

A simple little framework for making Java CLI applications

License:Other


Languages

Language:Java 100.0%