-
Notifications
You must be signed in to change notification settings - Fork 441
Closed
Milestone
Description
Hi!
I'm trying to use the parseWithHandler method of CommandLine to delegate calls to my subcommands automatically, but it doesn't seem to work with SpringBoot (dependencies are not autowired).
Here is my Application class:
@SpringBootApplication
public class Application implements CommandLineRunner {
@Autowired
private ForHRMCommand mainCommand;
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) {
CommandLine command = new CommandLine(mainCommand);
command.parseWithHandler(new CommandLine.RunLast(), args);
}
}
The commands I created:
@Component
@Command(
name = "forhrm",
subcommands = {
ServicesCommand.class
},
description = "Command to interact with your ForHRM installation"
)
public class ForHRMCommand implements Callable<Void> {
@Option(names = "--start", description = "Starts ForHRM FrontOffice") private boolean start;
@Option(names = "--with-services", needs = "--start", description = "Starts the services as well") private boolean withServices;
@Autowired
private ServicesCommandService servicesCommandService;
@Override
public Void call() {
...
}
}
@Component
@Command(name = "services")
public class ServicesCommand implements Callable<Void> {
...
@Autowired
private ServicesCommandService service;
...
}
And finally a service I intend to use:
@Service
public class ServicesCommandServiceImpl implements ServicesCommandService {...}
When I try to execute the subcommand, it fails because the service is null. Is it not supported yet?
Thanks a lot!
Metadata
Metadata
Assignees
Labels
No labels