Created
July 5, 2019 14:28
-
-
Save netodevel/c76cc21ddef201640e6f32117446a914 to your computer and use it in GitHub Desktop.
integration cli error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | |
} | |
} |
Author
netodevel
commented
Jul 5, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment