Open plinto
Docs›Reference

Tasks

Reference

A task is a command of your project's own. Put a file in its tasks/ folder, and plinto <name> runs it, with every argument after the name.

$ plinto fmt --check
src/greet.go
$ echo $?
1

Files

File Runs with
tasks/fmt.sh bash, whatever its #! line says (Git's bash on Windows)
tasks/reset.lua Lua 5.4, which plinto carries: nothing to install
tasks/DbReset.java java, as a source file: the project's JDK, else the one plinto runs on

How a task runs

Variable What it holds
PLINTO_PROJECT, PLINTO_VERSION the project's name and version
PLINTO_PROJECT_DIR, PLINTO_BUILD_DIR the project's folder and its build/
PLINTO_WORKSPACE_DIR the workspace's folder, when there is one
PLINTO_TASK the task's name
PLINTO_CLI the plinto that started it, which runs on plinto's own Java whatever JAVA_HOME says
PLINTO_TOOLS a folder per tool, named after it: $PLINTO_TOOLS/Go, and the packages it brings
PATH the build dependencies' bin/ folders, then yours
JAVA_HOME when a build dependency is a JDK

Everything else your shell has is there too: your credentials, SSH_AUTH_SOCK. A tool only a task uses, such as a linter, goes in build-dependencies too. A project without a version group, outside a workspace, runs its tasks with your PATH's tools, and plinto warns when it declares some.

Lua tasks

Lua is the portable kind: a real language, the same on macOS, Linux and Windows, with no bash. The plinto table adds what Lua lacks.

tasks/reset.lua
-- Deletes generated code and the local database, then seeds again; --keep-db keeps the database
local keep_db = plinto.args[1] == "--keep-db"

plinto.delete("build/generated")
for _, file in ipairs(plinto.glob("src/**/*_gen.go")) do
  plinto.delete(file)
end

local db = plinto.project.build_dir .. "/greeter.db"
if not keep_db then
  plinto.delete(db)
end

plinto.env.GREETER_DB = db             -- what the commands below get
local code = plinto.cli{ "run", "--", "--seed" }
if code ~= 0 then
  plinto.fail("seeding failed with exit code " .. code)
end
Lua What it does
plinto.args the arguments, a list; Lua's arg and ... have them too
plinto.project name, version, dir, build_dir; also plinto.workspace_dir and plinto.task
plinto.tools each tool's version and dir: plinto.tools.Go.version
plinto.env the environment: setting a key changes what the commands the task runs get
plinto.exec{cmd, …} runs a command with the terminal, with no shell in between, and returns its exit code
plinto.output{cmd, …} the same, returning its output; a command that fails is an error
plinto.cli{…} runs this plinto: plinto.cli{"build"}
plinto.delete(path) a file, or a folder with everything in it; one that isn't there is fine. Only within the project's folder
plinto.copy(from, to), plinto.move(from, to) files or folders
plinto.mkdir(path) with its parents
plinto.exists(path), plinto.list(folder) whether it's there; the names in a folder
plinto.glob(pattern) the project's files that match: * within a folder, ** across folders
plinto.read(path), plinto.write(path, text) a whole file as text
plinto.fail(message) prints error: message and exits with 1

Paths are relative to the project's folder. An error names the task's file and line, as tasks/reset.lua:4: plinto.delete: ../Other is outside Greeter's folder, and exits with 1. os.exit(n) exits with n. require("lib.common") loads tasks/lib/common.lua.

Java tasks

tasks/DbReset.java
// Drops and creates the local database again; --yes doesn't ask first
void main(String[] args) throws Exception {
    var db = "greeter_" + System.getenv("USER");
    if (!List.of(args).contains("--yes") && !IO.readln("Drop " + db + "? [y/N] ").equals("y")) {
        return;
    }
    run("dropdb", "--if-exists", db);
    run("createdb", db);
}

void run(String... command) throws Exception {
    int code = new ProcessBuilder(command).inheritIO().start().waitFor();
    if (code != 0) System.exit(code);
}

plinto db-reset runs java tasks/DbReset.java with the project's JDK when its build-dependencies have one, such as Java = 25, else with the Java plinto runs on. A file without a class needs Java 25; on an older one, declare a class with a static void main. Helpers go in a package folder, such as tasks/lib/Db.java with package lib;. A task gets the JDK, not the project's classes or libraries.