Skip to main content

cli_handle_version_or_continue

Function cli_handle_version_or_continue 

Source
pub fn cli_handle_version_or_continue(
    raw_args: &[String],
    name: &str,
    version: &str,
) -> Result<Option<String>, Event>
Expand description

Render version output from raw argv if --version or -V is present.

raw_args should be the full argv vector, including argv[0], as produced by std::env::args(). The helper intentionally runs before clap or another parser so explicit --output json|yaml|plain is honored instead of being bypassed by built-in version handling.

Only a top-level version request is recognized: scanning stops at the first positional argument (the subcommand), so tool sub --version <value> leaves --version for the subcommand’s parser rather than printing the tool version.

The one blessed behavior: a bare --version prints conventional <name> <version> text; an explicit --output json|yaml|plain (or --json) prints a protocol-v1 kind:"result" version event (payload { "code": "version", "version": ... }). Returns a standard build_cli_error event when the request is malformed, for example --version --output xml.