Most validation is done when the arguments are parsed:

Object[][][] spec = {
		{ { "foo", Integer.class }, {}, { Cli.Res.REQUIRED } },
		{ { "corge", Double.class }, {}, { Range.incl(0, 10) } },
		{ { "bar", Integer.class } }, 
		{ { Cli.Opt.ARGS, "baz" } }
Cli cli = new Cli(spec);
cli.parse("--bar", "quux", "--corge", "11");
	argument 1, <baz>, not defined
	--foo is required but has no defined value
	--corge: 11.0 outside range [0, 10]
	--bar: --bar expects an integer argument; received quux

USAGE: EXECUTABLE [options] <baz>

	--foo   <val>  whole number option; REQUIRED
	--corge <val>  floating point numerical option
	--bar   <val>  whole number option

It may still be the case, however, that after parsing some validation is required. Perhaps there are interactions among options that are not expressible in the specification or the arguments must be validated further. dfh.cli.Cli provides three methods which are useful in this case.


As you proceed in your validation you may encounter more than one error. You register each error with the error(String) method.

if (cli.argument("foo") == null && cli.bool("bar"))
	cli.error("null --foo while --bar");


Once your validation code is done, you call errorCheck() . This will cause the executable to exit with usage information if any errors were registered.


If after discovering some error you simply wish to abort further processing, you call die(String) with the error message.