Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
integration cli error
public class TemplateCommand extends OptionParsingCommand {
public TemplateCommand(String name, String description, OptionHandler handler) {
super(name, description, handler);
}
@Override
public String getUsageHelp() {
return "[options] <template>";
}
}
public class TemplateHandler extends OptionHandler {
private Logger log = LoggerFactory.getLogger(TemplateHandler.class);
private OptionSpec<String> template;
private OptionSpec<Void> listTemplates;
private List<String> templates = Collections.singletonList("jms-aws-sqs");
@Override
protected void options() {
this.template = option(Arrays.asList("template", "t"), "name of template").withRequiredArg();
this.listTemplates = option(Arrays.asList("list"), "list of available templates");
}
@Override
protected ExitStatus run(OptionSet options) {
String template = (String) options.valueOf("t");
if (templateNotExists(template)) return ExitStatus.ERROR;
if (options.has(this.listTemplates)) output();
if (options.has(this.template)) return executeTemplate(template);
return ExitStatus.ERROR;
}
private ExitStatus executeTemplate(String template) {
System.out.println("Generate config to: ".concat(template));
if (template.equals("jms-aws-sqs")) {
try {
new MessageListenerGenerator().generateConfig("MessageListener", "jms_aws_sqs/template-message-listener.txt");
} catch (IOException e) {
return ExitStatus.ERROR;
}
}
return ExitStatus.OK;
}
private boolean templateNotExists(String template) {
if (template != null && !template.isEmpty()) {
if (!templates.contains(template)) {
System.out.println("template ".concat(template).concat(" not found. Use --list to see available template"));
return true;
}
}
return false;
}
private void output() {
System.out.println("Templates available");
System.out.println("* jms-aws-sqs");
}
}
public class ScaffoldFactoryCommands implements CommandFactory {
public Collection<Command> getCommands() {
return Arrays.<Command>asList(
new ModelCommand("model", "generate entities", new ModelHandler()),
new RepositoryCommand("repository", "generate repositories", new RepositoryHandler()),
new ServiceCommand("service", "generate services", new ServiceHandler()),
new ControllerCommand("controller", "generate controllers", new ControllerHandler()),
new ScaffoldCommand("scaffold", "generate api scaffold", new ScaffoldHandler()),
new SetupScaffoldCommand("setup:scaffold", "setup scaffold", new SetupScaffoldHandler()),
new TemplateCommand("template", "generate setup project", new TemplateHandler()));
}
}
@NetoDevel

This comment has been minimized.

Copy link
Owner Author

@NetoDevel NetoDevel commented Jul 5, 2019

$ spring template --list
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.NoSuchMethodError: br.com.netodevel.command.template.TemplateHandler.option(Ljava/util/Collection;Ljava/lang/String;)Ljoptsimple/OptionSpecBuilder;
        at br.com.netodevel.command.template.TemplateHandler.options(TemplateHandler.java:27)
        at org.springframework.boot.cli.command.options.OptionHandler.getParser(OptionHandler.java:68)
        at org.springframework.boot.cli.command.options.OptionHandler.run(OptionHandler.java:83)
        at org.springframework.boot.cli.command.OptionParsingCommand.run(OptionParsingCommand.java:54)
        at org.springframework.boot.cli.command.CommandRunner.run(CommandRunner.java:219)
        at org.springframework.boot.cli.command.CommandRunner.runAndHandleErrors(CommandRunner.java:171)
        at org.springframework.boot.cli.SpringCli.main(SpringCli.java:63)
        ... 8 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.