views:

1336

answers:

7

I need to write a simple command-line application in Java. It would be nice to use a library that takes care of parsing commands and takes care of things like flags and optional/mandatory parameters...

UPDATE

Something that has built-in TAB completion would be particularly great.

+7  A: 

Have a look at arg4j.

Pedro Henriques
+12  A: 

I've used the Apache Commons CLI library for command-line argument parsing. It's fairly easy to use and has reasonably good documentation.

Which library you choose probably comes down to which style of options you prefer ("--gnu-style" or "-javac-style").

Kevin ORourke
+5  A: 

JLine looks helpful.

JLine is a Java library for handling console input. It is similar in functionality to BSD editline and GNU readline. People familiar with the readline/editline capabilities for modern shells (such as bash and tcsh) will find most of the command editing features of JLine to be familiar.

And it does list tab completion in its features.

Michael Myers
+1; readline was the first thing that came to mind for me, and this seems to be the Java equivalent.
Adam Jaskiewicz
I actually found this by Googling for "readline java library". :)
Michael Myers
+2  A: 

In our company we are using JewelCli that uses an annotated Java interface definition to describe the Command Line Interface in a declarative style.

Light and simple to use, I'll recommend it.

madgnome
No Tab-completion for jewelcli, it's just a basic (but great) command line arguments parser.
madgnome
+1  A: 

There is a Java port of GNU getopt library for command line parsing. For command editing and TAB completion there is JLine (as mmyers has already recommended).

eneset
+1  A: 

I have used the Java Simple Argument Parser extensively. It handles all sorts of option types, has a well-designed and library (including the option to write custom parsers), and provides good documentation both in the JavaDocs and online.

I think your desire for tab completion would be taken care of by the shell rather than the command-line parsing library.

Brett Daniel
A: 

I have used JSAP. I have found it to be stable and well documented.

I am not sure I understand what you mean by "built-in TAB completion". Can you elaborate.

Parag