An ultra-lightweight command-line arguments parser and annotation-based mapping library for Java.
No magic. No reflection proxies. Just simple, robust, readable code that lets you parse command-line arguments without tears or ceremony.
- Simple fluent API (
Args.from(...).get(...)) - Support for boolean flags, aliases, default values
- Positional arguments
- Annotation-based mapping into POJOs
- Help message generator from annotations
- Quote-aware string tokenizer
- Zero external dependencies
- 100% pure Java
String[] args = {"--host", "localhost", "--port", "8080", "--debug"};
Args a = Args.from(args);
String host = a.get("--host", String.class); // "localhost"
int port = a.get("--port", Integer.class); // 8080
boolean debug = a.has("--debug"); // truepublic class Opts {
@ArgOption(names = {"--host", "-h"})
public String host = "localhost";
@ArgOption(names = {"--port", "-p"})
public int port = 8080;
@ArgOption(names = {"--debug", "-d"}, usage = "Enable debug mode")
public boolean debug;
@ArgPositional(index = 0, usage = "Input file")
public String input;
@ArgPositional(index = 1, usage = "Output file")
public String output;
}
String[] argv = {"-h", "127.0.0.1", "input.txt", "output.txt"};
Opts opts = Args.parse(argv, new Opts());System.out.println(Args.generateHelp(Opts.class, "my-app"));Output:
Usage: my-app [options] <input> <output>
Options:
--host, -h (default: localhost)
--port, -p (default: 8080)
--debug, -d Enable debug mode
Arguments:
input Input file
output Output file
- Writing tiny CLI utilities and tools
- Testing scripts with custom args
- Game dev tools (build pipeline, asset packaging)
- Replacing brittle manual parsing
- Annotated configuration parsing
Apache License 2.0
Built with insomnia, keyboard crumbs, and a deeply questionable relationship with
String[] args.