Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to PicocliRunner.execute(Class<?>, ApplicationContext, String...) does not compile #426

Open
miguelaferreira opened this issue Jan 9, 2025 · 0 comments

Comments

@miguelaferreira
Copy link

Expected Behavior

That a call to PicocliRunner.execute(Class<?>, ApplicationContext, String...) with any Class instance would compile.

Actual Behaviour

The compiler complaints that the Class instance I'm providing to the method does not comply with the method signature.

error: no suitable method found for execute(Class<CAP#1>,ApplicationContext,String[])
            PicocliRunner.execute(commandClass, ctx, args);
                         ^

Steps To Reproduce

  1. Create a Micronaut Cli app
  2. Declare a command class that does not implement Runnable nor Callable. (This is how Picocli recommends making subcommands required.)
import picocli.CommandLine;

@CommandLine.Command(
        name = "test-command",
        subcommands = {SubCommand.class}
)
public class TestCommand {
}

@CommandLine.Command(
        name = "sub-command"
)
public class SubCommand implements Runnable {

    @Override
    public void run() {
        System.out.println("Hello from SubCommand");
    }
}
  1. Create a test that calls PicocliRunner.execute(Class<?>, ApplicationContext, String...) with the command class as the first argument to the method.
import io.micronaut.configuration.picocli.PicocliRunner;
import io.micronaut.context.ApplicationContext;
import io.micronaut.context.env.Environment;
import org.junit.jupiter.api.Test;

class TestCommandTest {

    @Test
    void execute() {
        try (ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)) {
            String[] args = new String[]{};
            final Class<?> commandClass = TestCommand.class;
            PicocliRunner.execute(commandClass, ctx, args);
        }
    }
}

Environment Information

  • OS: Mac 15.2 (24C101)
  • Java 21

Example Application

No response

Version

4.7.3

@miguelaferreira miguelaferreira changed the title Cannot call PicocliRunner.execute(Class<?>, ApplicationContext, String...) due to type mismatch Cannot call PicocliRunner.execute(Class<?>, ApplicationContext, String...) due to type mismatch Jan 9, 2025
@miguelaferreira miguelaferreira changed the title Cannot call PicocliRunner.execute(Class<?>, ApplicationContext, String...) due to type mismatch Call to PicocliRunner.execute(Class<?>, ApplicationContext, String...) does not compile Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant