-
Notifications
You must be signed in to change notification settings - Fork 8
subcommands
H90 edited this page May 9, 2021
·
18 revisions
The @SuperCommand annotation can be used to create a command/subcommand structure.
The parser that's created by a @SuperCommand will stop parsing after the last @Parameter was read,
and return the remaining tokens as a String[] array. This array can then be passed to a @Command or even another @SuperCommand.
See this project, where something like this happens:
OperationCommand_Parser.OperationCommandWithRest result = new OperationCommand_Parser().parseOrExit(args);
Operation operation = result.getResult().operation();
String[] rest = result.getRest();
switch (operation) {
case UPLOAD -> new ArchiveMPU(new UploadArguments_Parser()
.parseOrExit(rest)).runUpload();
case DOWNLOAD -> {
DownloadArguments arguments = new DownloadArguments_Parser()
.parseOrExit(rest);
new ArchiveMPU(arguments).runDownload(arguments.downloadPath(), arguments.archiveId());
}
}