Parameters
Parameters are defined with a function header like syntax. Let's take a look at the "Hello World" example from here.
hello-world(location l: arg) {
action <% echo Hello World from $(location) %>
}
As you can see, our root toolchain supports a parameter, location
that you can
then reference in your action templates and even constants.
We also defined a shorthand, l
for our parameter.
Declare more than one parameter by separating them with a comma (,
)
Types
Currently, 2 types are supported:
arg
- a normal string valueflag
- a boolean value that is set to true if passed and set to false if omitted
Scope
The params that you define for a toolchain can be referenced in any descendant toolchain.
hello-world(location l: arg) {
action <% echo Hello World from $(location) %>
sub child {
action <% echo Hello Child from $(location) %>
}
}
$ hello-world Cluj-Napoca
Hello World from Cluj-Napoca
$ hello-world Cluj-Napoca child
Hello Child from Cluj-Napoca
Optionals
Optional arguments will not be mandatory when the toolchain is executed.
If a value is not passed for an optional, it will default to empty string in case of an arg
Flags are optional by default and their default value is false
They are marked with the question mark (?
) character at the end of their name.
When a parameter is optional, it is no longer passed in as a positional argument.
You will need to specify its name before the value.
hello-world(location l: arg?) {
action <% echo Hello World from $(location) %>
}
$ hello-world
Hello World from
$ hello-world --location Cluj-Napoca
Hello World from Cluj-Napoca
Defaults
Defaults are only supported for optional params.
hello-world(location l: arg? = "the other side") {
action <% echo Hello World from $(location) %>
}
$ hello-world
Hello World from the other side
$ hello-world -l Cluj-Napoca
Hello World from Cluj-Napoca