remkop/picocli

Method parse signature clash when using from Groovy

pditommaso opened this issue · 2 comments

It turns that when using picocli from groovy the following method signature

public static <T> T parse(T annotatedObject, String... args)

overrides

public List<Object> parse(String... args)

Thus in the following snippet it will try to invoke the static parse method interpreting the first string as the command object instead of a cli argument and resulting in an error.

        CommandLine parser = new CommandLine(new TopCommand())
                .addCommand("make", new MakeCmd())
                .addCommand("docker", new DockerCmd())
                .addCommand("cloud", new CloudCmd())

        List cli = parser.parse('cloud','create')

This makes difficult to use picocli in a groovy based project. Any chance to rename the static parse to a different name eg parseCommand ?

Good catch!

I'm thinking to leave the static method as it is, and instead rename the instance method to parseCommands.

The instance method is the one to use when parsing subcommands so it makes sense to me if this method has command in its name.

Also, I realized that the instance method has to change anyway: please see #134 (feedback welcome).

Reopening to revisit naming. See #139