mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
Merge pull request #2703 from clap-rs/hide_env
Remove TakesValue restriction for HideEnv*
This commit is contained in:
commit
257adbc882
4 changed files with 257 additions and 170 deletions
|
@ -84,9 +84,5 @@ fn assert_app_flags(arg: &Arg) {
|
|||
checker!(Last requires TakesValue);
|
||||
checker!(HideDefaultValue requires TakesValue);
|
||||
checker!(MultipleValues requires TakesValue);
|
||||
#[cfg(feature = "env")]
|
||||
checker!(HideEnv requires TakesValue);
|
||||
#[cfg(feature = "env")]
|
||||
checker!(HideEnvValues requires TakesValue);
|
||||
checker!(IgnoreCase requires TakesValue);
|
||||
}
|
||||
|
|
|
@ -3927,8 +3927,6 @@ impl<'help> Arg<'help> {
|
|||
///
|
||||
/// This is useful when the variable option is explained elsewhere in the help text.
|
||||
///
|
||||
/// **NOTE:** Setting this requires [`ArgSettings::TakesValue`]
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
|
@ -3967,8 +3965,6 @@ impl<'help> Arg<'help> {
|
|||
///
|
||||
/// This is useful when ENV vars contain sensitive values.
|
||||
///
|
||||
/// **NOTE:** Setting this requires [`ArgSettings::TakesValue`]
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
|
|
162
tests/help.rs
162
tests/help.rs
|
@ -549,60 +549,6 @@ FLAGS:
|
|||
-V, --version
|
||||
Print version information";
|
||||
|
||||
#[cfg(feature = "env")]
|
||||
static HIDE_ENV: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [OPTIONS]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
OPTIONS:
|
||||
-c, --cafe <FILE> A coffeehouse, coffee shop, or café.";
|
||||
|
||||
#[cfg(feature = "env")]
|
||||
static SHOW_ENV: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [OPTIONS]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
OPTIONS:
|
||||
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]";
|
||||
|
||||
#[cfg(feature = "env")]
|
||||
static HIDE_ENV_VALS: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [OPTIONS]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
OPTIONS:
|
||||
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR]
|
||||
-p, --pos <VAL> Some vals [possible values: fast, slow]";
|
||||
|
||||
#[cfg(feature = "env")]
|
||||
static SHOW_ENV_VALS: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [OPTIONS]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
OPTIONS:
|
||||
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
||||
-p, --pos <VAL> Some vals [possible values: fast, slow]";
|
||||
|
||||
static CUSTOM_HELP_SECTION: &str = "blorp 1.4
|
||||
|
||||
Will M.
|
||||
|
@ -1733,114 +1679,6 @@ fn issue_1052_require_delim_help() {
|
|||
));
|
||||
}
|
||||
|
||||
#[cfg(feature = "env")]
|
||||
#[test]
|
||||
fn hide_env() {
|
||||
use std::env;
|
||||
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.hide_env(true)
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café.")
|
||||
.takes_value(true),
|
||||
);
|
||||
assert!(utils::compare_output(app, "ctest --help", HIDE_ENV, false));
|
||||
}
|
||||
|
||||
#[cfg(feature = "env")]
|
||||
#[test]
|
||||
fn show_env() {
|
||||
use std::env;
|
||||
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.hide_env(false)
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café.")
|
||||
.takes_value(true),
|
||||
);
|
||||
assert!(utils::compare_output(app, "ctest --help", SHOW_ENV, false));
|
||||
}
|
||||
|
||||
#[cfg(feature = "env")]
|
||||
#[test]
|
||||
fn hide_env_vals() {
|
||||
use std::env;
|
||||
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
let app = App::new("ctest")
|
||||
.version("0.1")
|
||||
.arg(
|
||||
Arg::new("pos")
|
||||
.short('p')
|
||||
.long("pos")
|
||||
.value_name("VAL")
|
||||
.possible_values(&["fast", "slow"])
|
||||
.about("Some vals")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.hide_env_values(true)
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café.")
|
||||
.takes_value(true),
|
||||
);
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"ctest --help",
|
||||
HIDE_ENV_VALS,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[cfg(feature = "env")]
|
||||
#[test]
|
||||
fn show_env_vals() {
|
||||
use std::env;
|
||||
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
let app = App::new("ctest")
|
||||
.version("0.1")
|
||||
.arg(
|
||||
Arg::new("pos")
|
||||
.short('p')
|
||||
.long("pos")
|
||||
.value_name("VAL")
|
||||
.possible_values(&["fast", "slow"])
|
||||
.about("Some vals")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.hide_possible_values(true)
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café.")
|
||||
.takes_value(true),
|
||||
);
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"ctest --help",
|
||||
SHOW_ENV_VALS,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_headers_headers() {
|
||||
let app = App::new("blorp")
|
||||
|
|
257
tests/help_env.rs
Normal file
257
tests/help_env.rs
Normal file
|
@ -0,0 +1,257 @@
|
|||
#![cfg(feature = "env")]
|
||||
|
||||
use std::env;
|
||||
|
||||
use clap::{App, Arg};
|
||||
|
||||
mod utils;
|
||||
|
||||
static HIDE_ENV: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [OPTIONS]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
OPTIONS:
|
||||
-c, --cafe <FILE> A coffeehouse, coffee shop, or café.";
|
||||
|
||||
static SHOW_ENV: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [OPTIONS]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
OPTIONS:
|
||||
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]";
|
||||
|
||||
static HIDE_ENV_VALS: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [OPTIONS]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
OPTIONS:
|
||||
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR]";
|
||||
|
||||
static SHOW_ENV_VALS: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [OPTIONS]
|
||||
|
||||
FLAGS:
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
|
||||
OPTIONS:
|
||||
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]";
|
||||
|
||||
static HIDE_ENV_FLAG: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [FLAGS]
|
||||
|
||||
FLAGS:
|
||||
-c, --cafe A coffeehouse, coffee shop, or café.
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information";
|
||||
|
||||
static SHOW_ENV_FLAG: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [FLAGS]
|
||||
|
||||
FLAGS:
|
||||
-c, --cafe A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information";
|
||||
|
||||
static HIDE_ENV_VALS_FLAG: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [FLAGS]
|
||||
|
||||
FLAGS:
|
||||
-c, --cafe A coffeehouse, coffee shop, or café. [env: ENVVAR]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information";
|
||||
|
||||
static SHOW_ENV_VALS_FLAG: &str = "ctest 0.1
|
||||
|
||||
USAGE:
|
||||
ctest [FLAGS]
|
||||
|
||||
FLAGS:
|
||||
-c, --cafe A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information";
|
||||
|
||||
#[test]
|
||||
fn hide_env() {
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.hide_env(true)
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café.")
|
||||
.takes_value(true),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(app, "ctest --help", HIDE_ENV, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_env() {
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café.")
|
||||
.takes_value(true),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(app, "ctest --help", SHOW_ENV, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hide_env_vals() {
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.hide_env_values(true)
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café.")
|
||||
.takes_value(true),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"ctest --help",
|
||||
HIDE_ENV_VALS,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_env_vals() {
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.value_name("FILE")
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café.")
|
||||
.takes_value(true),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"ctest --help",
|
||||
SHOW_ENV_VALS,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hide_env_flag() {
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.hide_env(true)
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café."),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"ctest --help",
|
||||
HIDE_ENV_FLAG,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_env_flag() {
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café."),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"ctest --help",
|
||||
SHOW_ENV_FLAG,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hide_env_vals_flag() {
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.hide_env_values(true)
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café."),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"ctest --help",
|
||||
HIDE_ENV_VALS_FLAG,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_env_vals_flag() {
|
||||
env::set_var("ENVVAR", "MYVAL");
|
||||
|
||||
let app = App::new("ctest").version("0.1").arg(
|
||||
Arg::new("cafe")
|
||||
.short('c')
|
||||
.long("cafe")
|
||||
.env("ENVVAR")
|
||||
.about("A coffeehouse, coffee shop, or café."),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
"ctest --help",
|
||||
SHOW_ENV_VALS_FLAG,
|
||||
false
|
||||
));
|
||||
}
|
Loading…
Reference in a new issue