From 2a2cf81977da7052b0a9c5ab913f7f7188e6572e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Greinhofer?= Date: Sun, 23 Aug 2020 18:11:30 -0500 Subject: [PATCH] Update the env var example for derive Updates the derive example handling environment variables to illustrate the case where it contains a sensitive value which should not be displayed on the help screen. Closes https://github.com/clap-rs/clap/issues/2101 --- clap_derive/examples/env.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/clap_derive/examples/env.rs b/clap_derive/examples/env.rs index 38ba425e..2f668601 100644 --- a/clap_derive/examples/env.rs +++ b/clap_derive/examples/env.rs @@ -1,7 +1,7 @@ //! How to use environment variable fallback an how it //! interacts with `default_value`. -use clap::Clap; +use clap::{ArgSettings, Clap}; /// Example for allowing to specify options via environment variables. #[derive(Clap, Debug)] @@ -18,6 +18,12 @@ struct Opt { /// Number of retries #[clap(long, env = "RETRIES", default_value = "5")] retries: u32, + + // If an environment variable contains a sensitive value, it can be hidden + // from the help screen with a special setting. + /// Secret token + #[clap(long, env = "SECRET_TOKEN", setting = ArgSettings::HideEnvValues)] + token: String, } fn main() {