33import java .io .File ;
44import java .io .IOException ;
55import java .util .ArrayList ;
6+ import java .util .Map ;
67
78import org .eclipse .emf .common .util .DiagnosticException ;
89import org .eclipse .emf .common .util .URI ;
2425import picocli .CommandLine ;
2526import picocli .CommandLine .Command ;
2627import picocli .CommandLine .Option ;
28+ import picocli .CommandLine .ParameterException ;
2729import picocli .CommandLine .Parameters ;
2830
2931@ Command (
@@ -78,6 +80,21 @@ protected URI getModelURI(URI contextURI) {
7880 @ Option (names = "--root-action-location" , description = "Root action location" )
7981 private String rootActionLocation ;
8082
83+ @ Option (
84+ names = "--command-path" ,
85+ split = "," ,
86+ description = {
87+ "Comma-separated list of command names" ,
88+ "help is generated for the last command" ,
89+ "in the path"
90+ })
91+ @ Description (
92+ """
93+ Use this option if you want to generate help not for the root
94+ command, but for a sub-command.
95+ """ )
96+ private String [] commandPath ;
97+
8198 @ Override
8299 protected int generate (Context context , ProgressMonitor progressMonitor ) throws IOException , DiagnosticException {
83100 Action rootAction = AppFactory .eINSTANCE .createAction ();
@@ -94,8 +111,23 @@ protected int generate(Context context, ProgressMonitor progressMonitor) throws
94111 }
95112 }
96113
114+ CommandLine command = rootCommand ;
115+ if (commandPath != null ) {
116+ for (String cmdName : commandPath ) {
117+ Map <String , CommandLine > subCommands = command .getSubcommands ();
118+ if (subCommands == null ) {
119+ throw new ParameterException (command , command .getCommandName () + " has no subcommands" );
120+ } else {
121+ CommandLine subCommand = subCommands .get (cmdName );
122+ if (subCommand == null ) {
123+ throw new ParameterException (command , command .getCommandName () + " does not have " + cmdName + " subcommand" );
124+ }
125+ command = subCommand ;
126+ }
127+ }
128+ }
97129 Action rootCommandAction = ActionHelpMixIn .createCommandLineAction (
98- rootCommand ,
130+ command ,
99131 documentationFactories ,
100132 progressMonitor );
101133
0 commit comments