Skip to main content

validate_format_for_command

Function validate_format_for_command 

Source
pub fn validate_format_for_command(
    cmd: &str,
    format: OutputFormat,
) -> Result<(), String>
Expand description

Validate that a --format is supported by a given subcommand.

Implements format-flag-strictness-v1: many commands previously silently fell back to plain JSON when given --format sarif or --format dot, creating a security false-trust hazard for CI integrators wiring up SARIF (e.g. GitHub code-scanning) — they would believe SARIF was being emitted when it was not.

Universal formats (json, text, compact) are always allowed. SARIF is allowed only on commands that emit a real SARIF document; DOT is allowed only on commands that emit a real Graphviz document. Anything else returns an error pointing the user at a supported format.

Returns Err(message) for the (cmd, format) pairs that should be rejected; the caller (typically run_command in main.rs) is expected to surface the message to the user and exit with a non-zero status.