Juggernaut.CLI (Juggernaut v0.4.0)

Copy Markdown View Source

Runs a Juggernaut.CLI.Task: parses argv, prints --help, executes, reports errors and returns the exit code (design notes §3).

Output goes through Mix.shell/0. An error is printed to stderr as error: message, or, when the requested format is agent or json, as one JSON document on stdout:

{"format":1,"kind":"error","exit_code":2,"error":{"type":"usage","message":"..."}}

Summary

Functions

The agent/JSON error document (see the agent output guide), keys in a stable order.

The --format option for a task that offers choices. A JUGGERNAUT_FORMAT naming a format this task does not offer is ignored, so one setting serves every task.

Runs task with argv and ends the Mix task with its exit code.

Prints error in format and returns its exit code.

Runs task with argv in ctx and returns the exit code.

Functions

error_document(error, code)

The agent/JSON error document (see the agent output guide), keys in a stable order.

format_option(choices)

@spec format_option([atom()]) :: keyword()

The --format option for a task that offers choices. A JUGGERNAUT_FORMAT naming a format this task does not offer is ignored, so one setting serves every task.

main(task, argv)

@spec main(module(), [String.t()]) :: :ok | no_return()

Runs task with argv and ends the Mix task with its exit code.

report(error, format)

Prints error in format and returns its exit code.

run(task, argv, ctx)

Runs task with argv in ctx and returns the exit code.