JOpt Simple 4.5 包含一些小的增强,包括:
- Resolved gh-17 by offering OptionParser.nonOptions() and NonOptionArgumentSpec.
- Resolved gh-27 by offering OptionParser.allowsUnrecognizedOptions().
JOpt Simple 是一个简单的、测试驱动的命令行解析器,支持 POSIX getopt() 和 GNU getopt_long()
示例代码:
01 |
package joptsimple.examples; |
03 |
import joptsimple.OptionParser; |
04 |
import joptsimple.OptionSet; |
05 |
import org.junit.Test; |
06 |
import static org.junit.Assert.*; |
08 |
public class ShortOptionsTest { |
10 |
public void supportsShortOptions() { |
11 |
OptionParser parser = new OptionParser( "aB?." ); |
13 |
OptionSet options = parser.parse( "-a" , "-B" , "-?" ); |
15 |
assertTrue( options.has( "a" ) ); |
16 |
assertTrue( options.has( "B" ) ); |
17 |
assertTrue( options.has( "?" ) ); |
18 |
assertFalse( options.has( "." ) ); |