用于解析命令行参数的Java库? [英] Java library for parsing command-line parameters?
本文介绍了用于解析命令行参数的Java库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Java中写了一个小命令行应用程序。此应用程序应该使用混合的参数和命令,类似于 svn
。
示例
app url command1
app url command2 --parameter2 -x
app url command1 --param-with-argument argument
app --parameter url command1
app --no-url command2
app --help
希望
- 存在一个易于使用的Java库
>解决方案
我是 Commons CLI 的粉丝。 p>
您可以将其设置为理解命令,标志(具有短名称和长名称),是否需要某些命令/开关,或者是否具有默认值。它甚至具有打印出有用的 - help
类型消息的功能。
使用方案页面有一些很好的使用方法。
I write a little command-line-application in Java. This application should work with a mix of parameters and commands, similar to svn
.
Examples
app url command1
app url command2 --parameter2 -x
app url command1 --param-with-argument argument
app --parameter url command1
app --no-url command2
app --help
Wanted
- Exists an easy-to-use library for Java
- Supports parsing of such command-lines
- (Bonus) Automatically creates an appropriate help
解决方案
I'm a fan of Commons CLI.
You can set it to understand commands, flags (with short and long names), whether or not certain commands/switches are required, or if they have default values. It even has functionality to print out a useful --help
type message.
The Usage Scenarios page has some good examples of how it can be used.
这篇关于用于解析命令行参数的Java库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文