pub trait EnvPrefix {
// Required method
fn env_prefix(self, prefix: &str) -> Self;
}Expand description
Binds each long option of a Command and of every subcommand to
<PREFIX>_<LONG>, so the environment can set any flag a CLI declares.
Put it on the root parser as a derive attribute, with the trait in scope
(the prelude exports it): #[command(env_prefix = "VERCTL")]. Clap’s
derive applies a root attribute after it has added every argument and
subcommand, so C::command() returns the bound graph to help, the Usage
spec, the pre-parse view, and the parse alike.
A command-line flag wins over its variable, which wins over the default,
once env_under_flags has run before the parse. A CLI that also reads a
config file applies a file value only where neither was given.
An option is left unbound when it already declares its own env (the
override), has no long name, is hidden, is the --no-* side of a pair,
or is help or version. Not calling env_prefix disables the binding.
Required Methods§
Sourcefn env_prefix(self, prefix: &str) -> Self
fn env_prefix(self, prefix: &str) -> Self
Bind every eligible long option under prefix.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".