Skip to main content

must_confirm

Function must_confirm 

Source
pub fn must_confirm(
    action: &str,
    yes: bool,
    json: bool,
    processes: &[Process],
    not_found: Option<&[String]>,
) -> Result<bool>
Expand description

Whether a command that changes processes should ask before acting.

The convention is the same in every output format: changing a process needs a yes. --yes gives it up front (Ok(false): go ahead without asking); otherwise a person is asked (Ok(true)). --json only changes how results are printed, so it never stands in for --yes, and without a terminal there’s nobody to ask: both are refused with exit 4 before anything is touched. --dry-run never gets here; it previews without one.

Both refusals carry processes, the ones the command would have changed, so a caller reading the JSON error can see what a retry with --yes hits. A command that takes targets also passes not_found, the ones that matched nothing, which the refusal carries too.