Skip to content

Capacity to add (mix in) multiple command objects #144

@kakawait

Description

@kakawait

I just started using Picocli and what I understand (I may wrong) you can have only a single command to describe main options. I mean

CommandLine.populateCommand(new Example(), args);

or

new CommandLine(new Example());

Only take single command.

It could be cool to pass collections of command that will be merged. For example

CommandLine c = new CommandLine();
c.addCommand(new Generic());
c.addCommand(new Example());

Thus it will allow user to split their command options into multiple files (without using inheritance, here the concept is more composition).

with

class Generic {
    @Option(names = {"-V", "--version"}, help = true, description = "Prints version information and exits")
    private boolean versionRequested;

    @Option(names = {"-h", "--help"}, help = true, description = "Prints this help message and exits")
    private boolean helpRequested;
}

and

class Example {
    @Option(names = {"-f", "--foo"})
    private boolean foo;

    @Option(names = {"-b", "--bar"})
    private boolean bar;

    @Parameters(arity = "1..*", paramLabel = "FILE", description = "File(s) to process.")
    private File[] inputFiles;
}

At end result should be similar than merging both command like

class VirtualMergedResult {
    @Option(names = {"-V", "--version"}, help = true, description = "Prints version information and exits")
    private boolean versionRequested;

    @Option(names = {"-h", "--help"}, help = true, description = "Prints this help message and exits")
    private boolean helpRequested;

    @Option(names = {"-f", "--foo"})
    private boolean foo;

    @Option(names = {"-b", "--bar"})
    private boolean bar;

    @Parameters(arity = "1..*", paramLabel = "FILE", description = "File(s) to process.")
    private File[] inputFiles;
}

So yes Example could extends Generic but if we need more composition it will be hell :)


Feature is similar to JCommander .addObject(...) that can be chained and thus add multiple commands (objects in JCommander words)


But it's maybe to far from current architecture, I can understand that is not yet implementable or acceptable

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions