Are there good Java libraries that facilitate buil

2019-01-21 07:34发布

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.

10条回答
beautiful°
2楼-- · 2019-01-21 08:09

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

查看更多
forever°为你锁心
3楼-- · 2019-01-21 08:14

Have a look at arg4j.

查看更多
Lonely孤独者°
4楼-- · 2019-01-21 08:16

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.

查看更多
走好不送
5楼-- · 2019-01-21 08:18

As you're searching for a library that eases developing an interactive shell application, I'd suggest Cliche.

查看更多
趁早两清
6楼-- · 2019-01-21 08:18

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.

查看更多
可以哭但决不认输i
7楼-- · 2019-01-21 08:18

It's also worth looking at --jopt-simple.

It 'attempts to honor the command line option syntaxes of POSIX getopt() and GNU getopt_long().' It seems to have some community traction, notably being the command line parsing lib of choice for the OpenJDK.

Also, as Brett mentioned, tab completion is typically provided by your shell - you would write shell functions to provide that desired functionality.

p.s. Sorry for the duplicate answer, but this question is almost identical to Java library for parsing command-line parameters?

查看更多
登录 后发表回答