This repo sever as place for experimentation with dynamic templates for func.
As a template developer I want to be able to create project files in a dynamic fashion. Current implementation only allows static files to be used to create project files. This is not suitable for instance for Java projects where package structure should be created in accordance with template user wishes.
There are many other possible usages, for instance if in the future cluster will support some kind of cloudevents discovery user may be prompted which cloudevents are interesting and the template could generate structure/class for it.
For this reason I propose a new mechanism for template creation.
I would like to call it dynamic templates
or executable templates
for now.
A dynamic template could be any executable
file (script binary) satisfying
executable contract.
Such an executable would be put into ~/.config/func/repositories
,
then func
can discover it and expose it to a user in a similar way the static templates are exposed.
- The
executable
shall support three sub-commands:runtimes
,templates
andcreate
. - The
runtimes
sub-command shall take no parameters.
The sub-command shall print a JSON array of string to standard output containing a list of supported runtimes. - The
templates
sub-command shall take exactly one parameter: runtime name. The sub-command shall print a JSON array of string containing a list of supported templates for given runtime. - The
create
sub-command shall accept exactly one argument: JSON object specified by FuncSpec structure.
The sub-command shall create func project files (including func.yaml) with given FuncSpec.Name and at specified FuncSpec.Root using runtime/template specified by FuncSpec.Runtime/FuncSpec.Template. - The
executable
may use stdio as it wills. For instance to prompt uses for additional information required for project creation (e.g. group and artifact ids for maven project). - The
executable
behaviour may be customized by environment variables.
To ease development of binaries satisfying executable contract we will offer Go
library.
The library is centered around Repository and Template interfaces.
Template author will not have to write all the boilerplate related to argument parsing or data serialization.
All that is needed is to implement aforementioned interfaces and then pass it to the
NewCommandFromRepository()
function,
and use it in main()
.