pub trait EnvPrefix: Sealed {
// Required method
fn env_prefix(self, prefix: &str) -> Self;
}cli only.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 = "TOY")].
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 any of these holds:
- it already declares its own
env, which is the override; - it has no long name, or is hidden;
- it is the
--no-*side of a pair; - it is help or version.
Not calling env_prefix disables the binding.
The trait is sealed: Command is its only implementation, and a type
outside ctl-core cannot add one. So a method can join it in a minor
release.
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".