Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Console Menu library - Is there an easy way to create command line menus?

Background

In Java, I want to make a simple, quick console app that provides a series of menus and takes user input, then calls certain methods and outputs other menus. Basically, I need to create a loop:

menu > user selection > action > menu > ...

Ultimately, I'm using this on top of an integration server using Apache Camel. I have a "quick and dirty" app I use to exercise some of the server routes as a development tool. I don't want to spend a lot of time on something so simple.

There has to be an easy way to do this. Consoles and menus on command lines have been around for decades! There must be a java library out there that does this well. I just haven't found one...

Question

Is there a library out there or some Apache utility, or anything that would make creating super quick, super simple console menus a piece of cake?

Example

With the proper tool, it should take less than 30 minutes to make a menu that functions like
git add -i

That is, I need to make something that functions similar to git Interactive commands, or any other console app, and I want to do so quickly.


EDIT:

The suggestion, below, to use "Cliche" worked pretty well, allowing me to just annotate some methods and have a menu built out of that, automatically. In case it helps someone, I wanted to include some important notes on getting Cliche working:

  1. The project has been moved to google code
  2. It doesn't appear to be maintained but in the issues section, jbachorik mavenized the project!
  3. Here are the only adjustments I needed to make to my POM:

Add a repo:

    <repository>
       <id>sonatype-nexus-snapshots</id>
       <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>

Add dependency:

    <dependency>
        <groupId>com.googlecode.cliche</groupId>
        <artifactId>cliche</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
like image 448
gMale Avatar asked Aug 03 '12 20:08

gMale


1 Answers

Take a look at Cliche

It uses @Command method annotations to rapidly create interactive console-based apps. Its type converters are basic but Camel's own extensive type converters could be configured to be used instead. It also offers extra functionality like listing available commands and convention-driven input abbreviations.

like image 181
robinhowlett Avatar answered Nov 13 '22 22:11

robinhowlett