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:
- belongs to an option the command line set;
- belongs to the other side of a
--x/--no-xpair the command line set; - belongs to an option that conflicts, either way, with one the command
line set: a
conflicts_withon either side, a single-choice group they share, or either side beingexclusive; - is empty, as a composite action sets an input it was not given;
- reads as a boolean flag’s default,
falsefor a flag that setstrue, 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.