pub struct CliSpec {
pub schema: String,
pub name: String,
pub version: String,
pub display_name: Option<String>,
pub build: Option<String>,
pub about: Option<String>,
pub shared_arguments: Vec<ArgSpec>,
pub lifecycle_output: OutputSpec,
pub exit_codes: Vec<ExitCodeSpec>,
pub commands: Vec<CommandSpec>,
}Expand description
Serializable version-one closed-world CLI registry.
Fields§
§schema: String§name: String§version: String§display_name: Option<String>Human-facing product name, distinct from the binary identity in name.
build: Option<String>Opaque build identifier (a git SHA, for example). The core only carries it; what it means is the host’s business.
about: Option<String>Arguments every command accepts, declared once.
Spliced into each command at build time and added to every combination’s
optional set, so nothing downstream — resolution, help, --docs — needs
to know they were shared. Serialized as their own list so a consumer in
another language reads the same declaration rather than N copies.
lifecycle_output: OutputSpec§exit_codes: Vec<ExitCodeSpec>Exit codes this CLI returns beyond the 0/1/2 AFDATA defines, rendered into the reference’s exit-code table. Without this the published reference documents only AFDATA’s three, so a tool that also returns, say, a partial-success code ships a document that contradicts its own binary — on exactly the code a caller needs to branch on.
commands: Vec<CommandSpec>Implementations§
Source§impl CliSpec
impl CliSpec
Sourcepub fn new(name: impl Into<String>, version: impl Into<String>) -> Self
pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self
Start a cli-spec-v1 registry.
pub fn about(self, about: impl Into<String>) -> Self
pub fn display_name(self, display_name: impl Into<String>) -> Self
Sourcepub fn build_id(self, build: impl Into<String>) -> Self
pub fn build_id(self, build: impl Into<String>) -> Self
Record an opaque build identifier. Named build_id because build()
already compiles the registry.
pub fn lifecycle_output(self, output: OutputSpec) -> Self
Sourcepub fn exit_code(self, code: u8, meaning: impl Into<String>) -> Self
pub fn exit_code(self, code: u8, meaning: impl Into<String>) -> Self
Declare an exit code this CLI returns beyond AFDATA’s 0/1/2, so the rendered reference documents what the binary actually does.
pub fn command(self, command: CommandSpec) -> Self
Declare an argument every command accepts, once.
AFDATA already parses --output, --stdout-file and friends at every
command; this is the same capability for an argument the application
owns, so a --config needed by six commands is written once instead of
six times and cannot drift between them.
It does not change where the argument may appear. The command path
is still matched against the leading tokens of argv, so tool --config x sub remains an error and tool sub --config x is the accepted form.
This is only about declaration, not position — a caller migrating from a
parser with interleaved global flags has to move them after the path.
A command with no combinations is skipped: it exists to carry help for its children, accepts nothing itself, and would otherwise fail the build for declaring an argument no combination covers.
Sourcepub fn build(self) -> Result<BuiltCliSpec, CliSpecError>
pub fn build(self) -> Result<BuiltCliSpec, CliSpecError>
Validate and compile the registry.