(bjo task)

Reference

Overview

What a project’s tasks.bjo imports: once, and running a program on the terminal.

;; tasks.bjo
(export build test)
(import (std prelude))
(import (bjo task))

(:doc build (summary "Builds the library."))
(: (-> void))
(defun (build)
  (once 'build (println "building")))

(:doc test (summary "Builds, then runs the tests."))
(: (-> void))
(defun (test)
  (build)
  (println "testing"))

bjo task runs the exported functions of a project’s tasks.bjo. Each one has a (:doc ...), which is its help, and its parameters are its command-line arguments: a required parameter is a positional argument, and #:dry-run #f of type bool is the flag --dry-run. A task returns void, which exits with 0, or int, which is the exit code. A task calls another as a function.

The arguments are parsed by (std argparse), so a wrong argument is an error before the task runs. Each type in a task’s signature has an ArgValue instance, and is in scope through tasks.bjo: from (std prelude), or a type that tasks.bjo declares or re-exports. A keyword’s default is copied into the generated entry point as it is written, so it is a literal, or a name that tasks.bjo exports. A keyword of type (Option T), (List T) or (Vec T) is None or empty when absent.

tasks.bjo exports only tasks and the types their arguments have, each with a (:doc ...). Helpers go in another module. A package that only the tasks need goes in the manifest’s (task-depends ...).

See also: once, task-run, task-run!

Reference

Functions

Macros

Functions

task-once!

function ↑ Functions

(: task-once! (-> Symbol (-> void) void))
(task-once! key body)

The function once expands to.

key
The key.
body
What to run, the first time.

See also: once

task-run

function ↑ Functions

(: task-run (-> (Vec string) (#:directory (Option string)) (Result Exception int)))
(task-run argv #:directory None)

Runs a program on the terminal and waits for it.

argv
The program, then its arguments, one word each.
#:directory
The working directory of the program. The default is the working directory of bjo task.
returns
The exit code, or Err when the program cannot be started.
(match (task-run ["git" "diff" "--quiet"])
  ((Ok 0) (println "no changes"))
  ((Ok _) (println "changes"))
  ((Err e) (raise e)))

The program has the standard input, output and error of bjo task, so what it writes is shown when it is written. The program is looked up on PATH. Each word is one argument: no shell splits or expands it. What the task has printed is flushed before the program starts, so the two outputs come in order. An empty argv panics.

See also: task-run!, once

task-run!

function ↑ Functions

(: task-run! (-> (Vec string) (#:directory (Option string)) void))
(task-run! argv #:directory None)

Runs a program on the terminal, and ends the task when it fails.

argv
The program, then its arguments, one word each.
#:directory
The working directory of the program, as for task-run.
(task-run! ["./build_std.sh"])
(task-run! ["./run_tests.py"])
(task-run! ["make"] #:directory (Some "vendor/zlib"))

It runs the program as task-run does. When the program exits with a code other than 0, the task ends with that code, and a line on standard error names the command. When the program cannot be started, the task ends with 127.

See also: task-run

Macros

once

macro ↑ Macros

(once key body ...)

Runs a body the first time the key is reached in this run of bjo task.

key
A Symbol: 'build.
body ...
What to run.

Later, with the same key, the body does not run. The key is stored before the body runs, so a body that reaches its own once does not run again, and a body that panics ends the run. The value is void: a task does its work for its effect.

See also: task-once!