-
Feature Request
-
Resolution: Done
-
Major
-
None
-
None
-
None
This feature request is for the command line part of aesh.
When printing the usage for an aesh command/group, we should also print:
- the base cli to run (java -jar <jar>)
- the parent groups that might be present before that particular group/command
E.g
Usage: <base cli> <parent groups> <final command/group> [<options>] ...
Right now we have no option to specify the base cli, and the parent groups do not appear in the usage.
Reproducer:
public class MainTest { @GroupCommandDefinition(name = "gp-main", description = "test", groupCommands = {SubGroupCommand.class}) public static class GroupCommand implements Command { @Option(shortName = 'h', overrideRequired = true, hasValue = false, required = true, description = "print help") private boolean help; Shell shell; public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { this.shell = commandInvocation.getShell(); if (help) { shell.writeln(commandInvocation.getHelpInfo("gp-main")); } System.out.println("Im in gp-main"); return CommandResult.SUCCESS; } } @GroupCommandDefinition(name = "gp-sub", description = "sub group", groupCommands = {MainCommand.class}) public static class SubGroupCommand implements Command { @Option(overrideRequired = true, hasValue = false) private boolean help; Shell shell; @Override public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { this.shell = commandInvocation.getShell(); if (help) { shell.writeln(commandInvocation.getHelpInfo("gp-sub")); } System.out.println("Im in gp-sub"); return CommandResult.SUCCESS; } } @CommandDefinition(name = "command", description = "main command") public static class MainCommand implements Command { @Option(overrideRequired = true, hasValue = false) private boolean help; Shell shell; public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { this.shell = commandInvocation.getShell(); if (help) { shell.writeln(commandInvocation.getHelpInfo("command")); } System.out.println("Im in main command"); return CommandResult.SUCCESS; } } public static void main(String[] args) throws Exception { CommandRegistry registry = new AeshCommandRegistryBuilder() .command(GroupCommand.class) .command(SubGroupCommand.class) .command(MainCommand.class) .create(); CommandRuntime runtime = AeshCommandRuntimeBuilder .builder() .commandRegistry(registry) .build(); System.out.println("--------------------------------------"); runtime.executeCommand("gp-main --help"); System.out.println("--------------------------------------"); runtime.executeCommand("gp-main gp-sub --help"); System.out.println("--------------------------------------"); runtime.executeCommand("gp-main gp-sub command --help"); System.out.println("--------------------------------------"); } }
Reproducer output:
--------------------------------------
Usage: gp-main
test
Options:
-h, --help print help
gp-main commands:
gp-sub sub group
Im in gp-main
--------------------------------------
Usage: gp-sub
sub group
Options:
--help
gp-sub commands:
command main command
Im in gp-sub
--------------------------------------
Usage: command
main command
Options:
--help
Im in main command
--------------------------------------
What I'd like to see:
--------------------------------------
Usage: <base-cli> gp-main [<options>] [COMMAND]
test
Options:
-h, --help print help
gp-main commands:
gp-sub sub group
Im in gp-main
--------------------------------------
Usage: <base-cli> gp-main gp-sub [<options>] [COMMAND]
sub group
Options:
--help
gp-sub commands:
command main command
Im in gp-sub
--------------------------------------
Usage: <base cli> gp-main gp-sub command [<options>]
main command
Options:
--help
Im in main command
--------------------------------------