Today it is possible to share a private state between top level commands using Command constructor. For example:
MySharedState state = ...;
This is not doable with sub commands. Sub command are created by Aesh Parser generator.
The only way to do it is via CliCommandInvocation but this makes the private state public (and this is not wanted in my case).
So I am suggesting to
- Use the already existing GroupCommand interface (that extends Command interface). It defines the method List<Command> getCommands().
- Change it to take a parameter.
- Makes my top level command to implement it and returns the sub commands instances.
- Make changes to the parser generator to check that the Command to parse is a GroupCommand and is annotated with GroupCommandDescription. If this is one, then call the getCommands method instead of creating them based on the Annotation content.
This state can be today shared with OptionActivator because the ProcessedCommand is passed along the Activator. For command activator that is not doable. The CommandActivator needs to align with the OptionActivator.