jbangdev / jbang

Unleash the power of Java - JBang Lets Students, Educators and Professional Developers create, edit and run self-contained source-only Java programs with unprecedented ease.
https://jbang.dev
MIT License
1.43k stars 159 forks source link

Add scaffolding templates for groovy with picocli #1277

Open benignbala opened 2 years ago

benignbala commented 2 years ago

Is your feature request related to a problem? Please describe. It would be convenient to have templates defined to create project scaffolds with groovy and picocli

Describe the solution you'd like Adding qute templates for initialising a groovy based cli project with picocli

Describe alternatives you've considered Alternative would be to initialise a hello groovy based project and manually add picocli dependencies

Additional context N/A

benignbala commented 2 years ago

I can try and raise a PR for this if others consider this idea/feature request useful.

nandorholozsnyak commented 2 years ago

Hey, Where would you like to add these templates? Into this JBang repository? JBang catalog is a good place to place your templates in it, you can create it in any git repository and you can wire those templates into your local environment with catalogs.

benignbala commented 2 years ago

@nandorholozsnyak - Initial thought was to have it in jbang repo so that all users will be able to use it. Please let me know your thoughts on that.

But being able to use from any git repo would be great. In the doc, I saw examples for catalogs and aliases, but they did not show using templates from a different repo. Could you please help me with how to pull in templates from a different repo? Will it be something like the usage below? Thanks


jbang alias --name groovy-picocli https://some.url/path/to/groovy-picocli-jbang.qute
jbang init -t groovy-picocli groovy-cli-util.groovy
nandorholozsnyak commented 2 years ago

Hey @benignbala

Yes it looks like this, your templates in the catalog are having "names" or at least "keys", as it sits in a JSON Map. When you add this catalog to your local environment you can add a nem for it as you did but when you run the init command you should reference that catalog where you want to read the template from like in this format: jbang init -t=<template-name>@<catalog-name> <filename>

jbang catalog add --name groovy-picocli https://some.url/path/to/groovy-picocli-jbang.qute   
jbang init -t groovy-picocli@groovy-picocli groovy-cli-util.groovy

But I advice you to add a general name to your catalog and not the same as your template.

For example here is what I use: https://github.com/nandorholozsnyak/jbang-cloud/blob/main/jbang-catalog.json

jbang catalog add --name jbang-cloud https://github.com/nandorholozsnyak/jbang-cloud/blob/main/jbang-catalog.json
jbang init  -t=q-aws-lambda@jbang-cloud Lambda.java

It will use that template: https://github.com/nandorholozsnyak/jbang-cloud/blob/main/jbang-catalog.json#L51

quintesse commented 2 years ago

jbang catalog add --name groovy-picocli https://some.url/path/to/groovy-picocli-jbang.qute

In your first example the URL would have to be to a catalog, not directly to the template. Your second example is correct though 👍

Btw, if you put your catalog in a GitHub, GitLab or BitBucket repo then you don't need to use the jbang catalog add, it will be automatically inferred. So you can do something like this:

jbang init -t helloworld@maxandersen hello.java

and it will just work. And if you don't want to call your repo jbang-catalog then you can also use something like:

jbang init -t helloworld@githubuser/myreponame hello.java

(this is just an example, it won't actually work).

benignbala commented 2 years ago

Thanks a lot @quintesse and @nandorholozsnyak. This helps a lot. I'll try this out.