-
Notifications
You must be signed in to change notification settings - Fork 9
subcommands
h908714124 edited this page Aug 13, 2026
·
19 revisions
A command with superCommand = true generates a parser that stops parsing after the last positional parameter was read,
and simply returns the remaining tokens:
@Command(
superCommand = true,
name = "git",
description = "Git is software for tracking changes in any set of files.")
interface GitCommand {
@Parameter(index = 0)
String command();
List<String> remainingTokens();
}The generated GitCommandParser can be used as follows:
GitCommand gitCommand = new GitCommandParser().parseOrExit(new String[]{"add", "foo"});
String command = result.command(); // command == "add"
List<String> remainingTokens = result.remainingTokens(); // remainingTokens == ["foo"]We can use another command interface to parse the remaining tokens.
@Command(
name = "git-add",
description = "Add file contents to the index")
interface AddCommand {
List<String> pathspec();
// maybe add more options here
}