ctl-core
The shared clap chassis for a family of command-line programs. It is a library, not a command.
A program built on ctl-core owns its typed requests and results. ctl-core owns the rest: parsing, help, shared flags, colour policy, terminal layout, streams, errors, exit codes, and JSON output. One serializable result feeds the pretty, colourless, and JSON output.
Clap types ──→ App ──→ typed domain result ──┬──→ JSON
└──→ Document ──→ pretty/colourless
Document is a tree of semantic blocks: headings, prose, fields, tables, sections, notices, rules, and verbatim text.
It holds meaning, not escape codes or table borders.
The renderer chooses style, wrapping, width, and colour, through the ctl-text, ctl-layout, and ctl-term crates.
What it provides
-h/--helpand-V/--version, rendered as documents and wrapped to the terminal's width.- Shared flags to flatten into the parser:
-c/--color,-f/--format,-n/--dry-run, and-q/--quiet. With#[command(env_prefix = "MYCTL")]on the root parser, every long option also readsMYCTL_<LONG>from the environment. - JSON on stdout only, never coloured, and human failures on stderr. Quiet hides only successful human output.
- A reader that closes stdout early, such as
head -1, leaves the exit code as the command set it.App::broken_pipe(BrokenPipe::Fail)turns every closed pipe into a failure. <bin> completion <SHELL>and<bin> init <SHELL>for bash, zsh, and fish, behind thecompletionandshell-initfeatures.- A loader for declared YAML or TOML input that validates once and reports every problem with its file and line, behind
input-yamlandinput-toml. Validation with garde is behindvalidate, andinputisinput-yamlwithvalidate.Input::placeturns aFieldPath, the steps down to a field, into its line and column, so a CLI places a problem of its own as the loader places garde's.
Example
use *;
use Serialize;
example status prints the field as a record.
example status --format json prints the same Status value as JSON, with no escape byte, whatever the terminal.
A failure in JSON mode prints an error envelope instead.
Features
The default feature is app.
Each feature turns on only what its code calls.
| Feature | Adds |
|---|---|
document |
Semantic documents, with no terminal engine |
render |
Renders documents to a String through ctl-text, ctl-layout, and the ctl-term encoder, with a replaceable Theme |
json |
Serde models and the JSON view |
view |
Pretty, JSON, and colourless output over one model, with ctl-term deciding colour and width |
cli |
Clap helpers (OutputArgs, DryRunArgs) and parser defaults |
help |
Styled help through the document renderer |
app |
The whole lifecycle: parse, run, present, and exit |
usage |
The mise Usage spec (--usage-spec) for a mounted task |
surface-model, surface-serde, surface-templates, surface |
The operator model drawn from the Clap types, its serialization, and shared MiniJinja fragments |
unsafe-chars |
unsafe_chars::is_unsafe and strip_unsafe, the characters never printed as they are |
schema |
JSON Schema for the envelope |
validate, input-yaml, input-toml, input |
Shared garde rules, and the declared-input loader for each format; input is input-yaml with validate |
served |
Files rendered from templates that name their own target |
shell, completion, shell-init |
The shell verbs |
fixture |
Temporary file trees for integration tests |
Documentation
The API reference is on docs.rs, with each feature and the items it enables.
License
MIT.