picocli icon indicating copy to clipboard operation
picocli copied to clipboard

"Parsed command (...) is not a Method, Runnable or Callable" not recognized by annotation processor

Open Vampire opened this issue 2 years ago • 8 comments

The "Parsed command (...) is not a Method, Runnable or Callable" error is not reported by the annotation processor, but only complained about at runtime in 4.6.3.

Vampire avatar May 03 '22 15:05 Vampire

@Vampire Can you show how to reproduce this?

remkop avatar May 03 '22 22:05 remkop

Just annotate a class that is not Runnable or Callable with @Command and build with annotation processor configured. The annotation processor will not complain but at runtime it fails.

Vampire avatar May 03 '22 22:05 Vampire

I see. thank you for the clarification. Are you interested in providing a pull request for this?

remkop avatar May 03 '22 22:05 remkop

Currently not, sorry. I'm too busy with other stuff and it does not bite me enough. :-)

Vampire avatar May 03 '22 23:05 Vampire

Understood. Thanks for letting me know!

remkop avatar May 04 '22 12:05 remkop

Also while reading the "Required Subcommands" section, I'd say that the error message is missing "and does not have subcommands" in which case it would have been valid.

Vampire avatar May 11 '22 17:05 Vampire

Sorry, I don't follow... Are you saying that the example in the Required Subcommands section, that currently looks like this:

@Command(name = "git", synopsisSubcommandLabel = "COMMAND", subcommands = { ... })
class Git implements Runnable {
    @Spec CommandSpec spec;

    public void run() {
        throw new ParameterException(spec.commandLine(), "Missing required subcommand");
    }

    public static void main(String... args) {
        System.exit(new CommandLine(new Git()).execute(args));
    }
}

Should look like this instead?

@Command(name = "git", synopsisSubcommandLabel = "COMMAND", subcommands = { ... })
class Git implements Runnable {
    @Spec CommandSpec spec;

    public void run() {
        throw new ParameterException(spec.commandLine(), "Missing required subcommand and does not have subcommands");
    }

    public static void main(String... args) {
        System.exit(new CommandLine(new Git()).execute(args));
    }
}

remkop avatar May 11 '22 21:05 remkop

No, that wouldn't make sense. I reported in this issue, that if you annotate a class that is not Runnable or Callable with @Command and build with annotation processor configured. The annotation processor will not complain but at runtime it fails with message "Parsed command (...) is not a Method, Runnable or Callable".

Additionally in this message "and does not have subcommands" is missing, as annotating a class that is not Runnable or Callable is fine if you have subcommands and just makes the subcommands mandatory.

Vampire avatar May 13 '22 07:05 Vampire