https://github.com/umjammer/klab-commons-cli
🍊 Java Command Line Interface w/ Annotation
https://github.com/umjammer/klab-commons-cli
annotation cli commons-cli java
Last synced: about 1 month ago
JSON representation
🍊 Java Command Line Interface w/ Annotation
- Host: GitHub
- URL: https://github.com/umjammer/klab-commons-cli
- Owner: umjammer
- Created: 2014-12-02T07:11:14.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-09-08T06:03:02.000Z (almost 2 years ago)
- Last Synced: 2025-12-28T14:30:38.997Z (6 months ago)
- Topics: annotation, cli, commons-cli, java
- Language: Java
- Homepage:
- Size: 89.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://jitpack.io/#umjammer/klab-commons-cli)
[](https://github.com/umjammer/klab-commons-cli/actions/workflows/maven.yml)
[](https://github.com/umjammer/klab-commons-cli/actions/workflows/codeql-analysis.yml)

# klab-commons-cli
Command Line Interface Library with Annotation
This is the wrapper of [Apache Commons CLI](http://commons.apache.org/proper/commons-cli/).
## Usage
* Before
```Java
Options options = new Options();
options.addOption(OptionBuilder
.hasArg(true)
.withArgName("output path")
.isRequired(true)
.withDescription("set the output path")
.create('d')
);
︙
CommandLineParser parser = new BasicParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
new HelpFormatter().printHelp("Foo", options, true);
System.exit(-1);
}
Foo foo = new Foo();
if (cmd.hasOption('d')) {
foo.outDir = cmd.getOptionValue('d');
}
︙
```
* After
```Java
@Options
public class Foo {
@Option(argName = "output path", option = "d", args = 1, required = true, description = "set the output path")
private String outDir;
:
public static void main(String[] args) throws Exception {
Foo foo = new Foo();
Options.Util.bind(args, foo);
︙
}
```
## References
* [apache-commons-cli](https://commons.apache.org/proper/commons-cli/)
## TODO
* add group functionality?
* add default value? (just set values into fields?)
* class binding
* rename project vavi-commomns-cli
* BasicParser is deprecated, but Default parser doesn't pass the unit test #test08