rad/task
Tasks represent commands that can be invoked from the rad
command line
interface.
A collection of tasks that can be handled by
rad.do_main
is called a
Workbook
.
Types
A type that describes an external source code formatter.
If a Task
uses formatters
as its
Iterable
, that task will run the gleam
formatter along with
any formatters defined in your gleam.toml
config via the rad.formatters
table array.
Examples
[[rad.formatters]]
name = "javascript"
check = ["rome", "ci", "--indent-style=space", "src", "test"]
run = ["rome", "format", "--indent-style=space", "--write", "src", "test"]
pub type Formatter {
Formatter(name: String, check: List(String), run: List(String))
}
Constructors
-
Formatter(name: String, check: List(String), run: List(String))
A value for the for
field of every Task
.
An Iterable
tells a Runner
which items to iterate over and
how input should be mapped at the beginning of each iteration.
A new
Task
defined in a
Workbook
, will ask its Runner
to
iterate Once
. This can be changed using the for
builder
function.
At runtime, when a Runner
sees that its Task
needs
to run for Each
of any number of items, it can proceed accordingly. A
trainer
does this for its Runner
automatically.
pub type Iterable(a) {
Each(
get: fn(CommandInput, Task(a)) -> List(String),
map: fn(CommandInput, Task(a), Int, List(String)) ->
CommandInput,
)
Once
}
Constructors
-
Each( get: fn(CommandInput, Task(a)) -> List(String), map: fn(CommandInput, Task(a), Int, List(String)) -> CommandInput, )
-
Once
A value for the config
and manifest
fields of every Task
.
A new
Task
defined in a
Workbook
, won’t ask its Runner
to
access the gleam.toml
or manifest.toml
files (None
). This can be
changed using the with_config
and/or
with_manifest
builder functions (Expected
).
At runtime, when a Runner
sees that its Task
needs
some Toml
data, it can fetch it once (Parsed
) and use
it repeatedly . A trainer
does this for its
Runner
automatically.
pub type Parser {
Expected
None
Parsed(Toml)
}
Constructors
-
Expected
-
None
-
Parsed(Toml)
A function that takes
CommandInput
and a
given Task
and does any number of things with them.
pub type Runner(a) =
fn(CommandInput, Task(a)) -> a
The basic configuration unit for the rad
command line interface.
A Task
can be conveniently built up using the following functions:
new
, followed by any number of shortdoc
,
flag
, flags
, parameter
,
parameters
, with_config
,
with_manifest
, and for
combined with
arguments
, formatters
,
packages
, targets
, or
, or a custom
Iterable
-generating function.
Any number of tasks can be added to a new
or existing
Workbook
, such as the standard
workbook
, to compose a custom
Workbook
that can be given to
rad.do_main
.
pub type Task(a) {
Task(
path: List(String),
run: Runner(a),
for: Iterable(a),
delimiter: String,
shortdoc: String,
flags: List(#(String, Flag)),
parameters: List(#(String, String)),
config: Parser,
manifest: Parser,
)
}
Constructors
-
Task( path: List(String), run: Runner(a), for: Iterable(a), delimiter: String, shortdoc: String, flags: List(#(String, Flag)), parameters: List(#(String, String)), config: Parser, manifest: Parser, )
Functions
pub fn arguments() -> Iterable(a)
pub fn basic(
command: List(String),
) -> fn(CommandInput, Task(Result(String, Snag))) ->
Result(String, Snag)
pub fn delimit(
iterable task: Task(a),
with delimiter: String,
) -> Task(a)
pub fn flag(
into task: Task(a),
called name: String,
explained description: String,
expect flag_fun: fn() -> FlagBuilder(b),
default value: b,
) -> Task(a)
pub fn flags(
into task: Task(a),
add flags: List(#(String, Flag)),
) -> Task(a)
pub fn for(
do task: Task(a),
each iter_fun: fn() -> Iterable(a),
) -> Task(a)
pub fn formatters() -> Iterable(a)
pub fn gleam(
arguments: List(String),
) -> fn(CommandInput, Task(Result(String, Snag))) ->
Result(String, Snag)
pub fn new(
at path: List(String),
run runner: fn(CommandInput, Task(Result(String, Snag))) ->
Result(String, Snag),
) -> Task(Result(String, Snag))
Returns a new Task
with the given path
and runner
, which is
assisted by a trainer
to reduce boilerplate code for common
scenarios.
The path
is a list of words that, when given in sequence using rad
’s
command line interface, invoke the Task
, which will then be
processed together with any other input arguments and run by the runner
.
For example, if rad
is invoked from the command line with
rad hearts gleam
, it will try to run a Task
with the path
:
["hearts", "gleam"]
.
pub fn or(
true_fun: fn() -> Iterable(a),
cond flag_name: String,
otherwise false_fun: fn() -> Iterable(a),
) -> fn() -> Iterable(a)
pub fn packages() -> Iterable(a)
pub fn parameter(
into task: Task(a),
with usage: String,
of description: String,
) -> Task(a)
pub fn parameters(
into task: Task(a),
add parameters: List(#(String, String)),
) -> Task(a)
pub fn path(
into task: Task(a),
insert path: List(String),
) -> Task(a)
Returns a new Task
with the given path
.
The path
is a list of words that, when given in sequence using rad
’s
command line interface, invoke the Task
, which will then be
processed together with any other input arguments and run by the runner
.
For example, if rad
is invoked from the command line with
rad hearts gleam
, it will try to run a Task
with the path
:
["hearts", "gleam"]
.
pub fn runner(
into task: Task(Result(String, Snag)),
insert runner: fn(CommandInput, Task(Result(String, Snag))) ->
Result(String, Snag),
) -> Task(Result(String, Snag))
pub fn shortdoc(
into task: Task(a),
insert description: String,
) -> Task(a)
Returns a new Task
with the given short documentation string.
pub fn sort(
tasks: List(Task(Result(String, Snag))),
) -> List(Task(Result(String, Snag)))
Sort Tasks
alphabetically by path
.
pub fn targets() -> Iterable(a)
pub fn tasks_from_config() -> List(
Result(Task(Result(String, Snag)), Snag),
)
Parses gleam.toml
for tasks defined in the [[rad.tasks]]
table array.
A defined Task
must have path
and run
key/values, and may
optionally have a shortdoc
key/value.
pub fn trainer(
runner: fn(CommandInput, Task(Result(String, Snag))) ->
Result(String, Snag),
) -> fn(CommandInput, Task(Result(String, Snag))) ->
Result(String, Snag)
Returns a Runner
that works with a given runner
to run its
Task
one or more times.
If the Task
contains an Iterable
, all runs are
attempted regardless of any failures along the way; however, the end
Result
will only be successful if no errors are produced.
Trainer runners are used for tasks defined in a
Workbook
.
pub fn with_config(task: Task(a)) -> Task(a)
pub fn with_manifest(task: Task(a)) -> Task(a)