Skip to main content

Module cli_spec

Module cli_spec 

Source
Expand description

Clap CLI introspection utilities for emitting a deterministic CLI spec JSON contract.

Responsibilities:

  • Convert an in-memory clap::Command (including hidden/internal commands and args) into the versioned CliSpec contract model.
  • Produce deterministic output by sorting commands/args and by emitting a stable JSON shape.

Not handled here:

  • Adding a user-facing CLI command that prints the spec (it is currently exposed only as the hidden/internal ralph __cli-spec command).
  • File IO, stdout/stderr printing, or schema generation.

Invariants/assumptions:

  • The caller provides the fully constructed clap command (e.g. Cli::command()).
  • Output ordering is deterministic: args are sorted by id, subcommands by name.

Functionsยง

cli_spec_from_command
Convert a clap command tree into the versioned CliSpec model.
cli_spec_json_pretty_from_command
Convert a clap command tree into deterministic pretty JSON.