JCommander has a nice feature that it refers to as commands. The example they give looks like this:
git commit --amend -m "Bug fix"
Is it possible to configure JCommander (or any other command line parser), to accept multiple commands? For example:
mycommand drawCircle -colour "red" -radius 5 drawCircle -colour "blue" -radius 8
This is what I've tried.
CommandDrawCircle.java
package omniplot.commandline;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
@Parameters(separators = "=", commandDescription = "Record changes to the repository")
public class CommandDrawCircle {
@Parameter(names = {"--colour", "-c"})
private String colour;
@Parameter(names = {"--radius", "-r"})
private int radius;
}
CommandMain.java
package omniplot.commandline;
import com.beust.jcommander.Parameter;
import java.util.ArrayList;
import java.util.List;
public class CommandMain {
@Parameter(names = "draw", description = "Information about what to draw")
private List<CommandDrawCircle> drawCommands = new ArrayList<>();
}
Main.java
public static void main(String[] args) throws ParseException {
CommandMain cm = new CommandMain();
JCommander jc = new JCommander(cm);
CommandDrawCircle draw = new CommandDrawCircle();
jc.addCommand("drawCircle", draw);
String cmd = jc.getParsedCommand();
That last line is where I am stuck. It only returns a single value, not a list of commands. Is there any way of having multiple commands?