pub fn env_under_flags(
command: Command,
raw: &[OsString],
) -> Result<Command, Error>cli only.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 function
parses raw once leniently to learn which options the command line set at
each subcommand level. It 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 with one the command line set. The
conflict may be a
conflicts_withon either side, a single-choice group they share, or anexclusiveoption on either side; - is empty. A wrapper that maps every setting to a variable may set one the caller left out. A GitHub Actions composite action does this with 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 function sees overrides only between --x/--no-x pairs, and no
conflict that a group declares. Call it on the command just before the
parse, and parse the command it returns. App does both.
§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.