parseFromInto
We have learned how to create an argument parser from a command template (ArgumentParser#from), how to parse the input with it (Command#parse), and finally, how to put the parsed values into the command template class instance (AfterParseOptions#into).
For performing these three steps, we usually write this code:
void main(String[] args) {
	var result = ArgumentParser.from(MyProgram.class)
		.parse(CLInput.from(args))
		.into(MyProgram.class);
}
Since this pattern is so common, Lanat provides a utility method that combines these three steps into one:
void main(String[] args) {
	var result = ArgumentParser.parseFromInto(MyProgram.class, args);
}
Providing custom after-parse actions
A more verbose overload of parseFromInto allows you to provide custom after-parse actions as well:
void main(String[] args) {
	var result = ArgumentParser.parseFromInto(
		MyProgram.class,
		CLInput.from(args),
		a -> a.printErrors().exitIfErrors()
	);
}
Last modified: 25 April 2024