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条回答
Melony?
2楼-- · 2019-01-21 08:19

I tried a few libraries and ended up using argparse4j. It's a really nice Java port of Python's argparse.

查看更多
男人必须洒脱
3楼-- · 2019-01-21 08:21

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).

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

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").

Update: picocli TAB completion recently became available and may be of interest. Not aware of any other command line parsing library that provides the command line completion requested in the OP.

查看更多
家丑人穷心不美
5楼-- · 2019-01-21 08:30

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.

查看更多
登录 后发表回答