CliParseWizard
Lightweight Java library for building command-line applications. Provides declarative command and argument definitions (flags, positional, key=value and multiple values), an input parser, validation, help generation and a simple command dispatcher.
Key features
- Declarative option and flag definitions with support for default values.
- Automatic help/usage generation and error handling.
- Support for positional arguments, flags, key=value and multiple-value arguments.
- Subcommands — register multiple commands in a single application.
- Small footprint and no runtime dependencies.
Installation (Maven)
<dependency>
<groupId>com.siperf</groupId>
<artifactId>cliparsewizard</artifactId>
<version>1.0.0</version>
</dependency>
Quick start
import com.siperf.cliparsewizard.CLIProcessor;
import com.siperf.cliparsewizard.ParsingResult;
import com.siperf.cliparsewizard.command.Command;
import com.siperf.cliparsewizard.argument.types.PositionalArgument;
import com.siperf.cliparsewizard.argument.types.FlagArgument;
public class QuickStart {
public static void main(String[] args) {
CLIProcessor processor = new CLIProcessor();
Command greet = processor.getCommandBuilder()
.setCommandName("greet")
.addArgument(new PositionalArgument("name", true, null))
.addArgument(new FlagArgument("verbose", false, null))
.setExecutable(result -> {
String name = (String) result.getParsedArguments().get("name");
boolean verbose = result.getParsedArguments().get("verbose") != null;
if (verbose) {
System.out.println("Hello, " + name + " (verbose)");
} else {
System.out.println("Hello, " + name);
}
})
.build();
String[] argv = args.length == 0 ? new String[] {"greet", "Alice", "--verbose"} : args;
ParsingResult res = processor.process(argv);
}
}
Examples and documentation
Detailed usage examples, architecture notes and API docs are available in the Docs section.
Implementation notes
- The parser supports long (`--name=value` / `--name value`) and short (`-n value`) options, positional arguments and accumulation of multiple values.
- Argument implementations provided: `FlagArgument`, `PositionalArgument`, `KeyValueArgument`, `MultipleValuesArgument`.
- For stricter typing (int/enum/file/URI) you can extend argument types or add custom parsers.
License
- Licensed under Apache 2.0 — License