Skip to main content

env_under_flags

Function env_under_flags 

Source
pub fn env_under_flags(
    command: Command,
    raw: &[OsString],
) -> Result<Command, Error>
Expand description

Removes each variable that the command line overrules, so the command line wins, and refuses two variables that conflict.

Clap treats a variable as given by the user: a variable that conflicts with a flag on the command line, or with its --no-* side, fails the parse (clap#5591). This parses raw once leniently to learn which options the command line set at each subcommand level, then unbinds each variable that:

  1. belongs to an option the command line set;
  2. belongs to the other side of a --x/--no-x pair the command line set;
  3. belongs to an option that conflicts, either way, with one the command line set: a conflicts_with on either side, a single-choice group they share, or either side being exclusive;
  4. is empty, as a composite action sets an input it was not given;
  5. reads as a boolean flag’s default, false for a flag that sets true, so it changes nothing and cannot conflict.

Clap keeps overrides_with and a group’s own conflicts_with private, so this sees overrides only between --x/--no-x pairs, and no conflict that a group declares. Call this on the command just before the parse, and parse the command it returns; App does.

§Errors

An ArgumentConflict error that names both variables when two remaining variables belong to conflicting options. Clap’s own error would name two flags the user never typed.