picocli icon indicating copy to clipboard operation
picocli copied to clipboard

InitializationException thrown by picocli-codegen on class without direct options

Open charphi opened this issue 4 years ago • 4 comments

InitializationException is thrown by picocli-codegen when ArgGroup is set on a class that has no direct options but extends one that has options.

Example:

@CommandLine.ArgGroup
SpecificOptions options;

static class GenericOptions {

    @CommandLine.Option(names = "--verbose")
    boolean verbose;
}

static class SpecificOptions extends GenericOptions {

    //@CommandLine.Option(names = "--dummy")
    //boolean dummyOption;
}

Stacktrace:

error: FATAL ERROR: picocli.CommandLine$InitializationException: ArgGroup has no options or positional parameters, and no subgroups: AnnotatedElementHolder(FIELD options in ArgGroupIssue) in null
        at picocli.CommandLine$Model$ArgGroupSpec.<init>(CommandLine.java:10059)
        at picocli.CommandLine$Model$ArgGroupSpec$Builder.build(CommandLine.java:10512)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor$Context.connectArgGroups(AbstractCommandSpecProcessor.java:997)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor$Context.connectModel(AbstractCommandSpecProcessor.java:856)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor$Context.access$000(AbstractCommandSpecProcessor.java:807)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor.tryProcess(AbstractCommandSpecProcessor.java:194)
        at picocli.codegen.annotation.processing.AbstractCommandSpecProcessor.process(AbstractCommandSpecProcessor.java:165)

Gist to reproduce:
https://gist.github.com/charphi/cd915fef9f38edec3994051217728669

charphi avatar Feb 01 '21 10:02 charphi

Sorry I have had little time to look into this...

Would the problem be resolved by putting the @ArgGroup annotation on the SpecificOptions class?

remkop avatar Feb 21 '21 02:02 remkop

No problem. It is a low-priority bug. I'm able to workaround it by adding a dummy hidden option.

charphi avatar Feb 22 '21 09:02 charphi

Can you explain the use case a bit? Why do you want to do this?

remkop avatar Feb 22 '21 09:02 remkop

I'm trying to create a library that can be shared between several cli projects. This library contains default options to (for example) read/write csv and yaml files. I need to extends these options if needed and sometimes I only add operations and not options.

charphi avatar Feb 22 '21 10:02 charphi