This is kind of a weird question, but I'm wondering if anyone knows whether this is possible. I want to display in my program's help text certain environment variables that can influence the behavior of the program that don't correspond to a CLI argument.
For example, consider the RUST_LOG
variable: it will be used by the telemetry library internally and has no value/effect when it is specified as a CLI argument. Nevertheless, I'd like to make the users aware of this value when help is invoked so that they know it exists.
use clap::Parser;
#[derive(Debug, Clone, Parser)]
struct Args {
/// Comma-delimited log directives to be used for filtering telemetry
#[clap(env = "RUST_LOG")]
rust_log: Option<String>,
}
fn main() {
let args = Args::parse();
println!("Parsed args: {args:?}");
}
Output:
Usage: clap-demo [RUST_LOG]
Arguments:
[RUST_LOG] Comma-delimited log directives to be used for filtering telemetry [env: RUST_LOG=]
Options:
-h, --help Print help
I don't see a way within clap to prevent this from showing as an argument but showing as an environment variable. I've tried the following, and it hides the argument altogether and displays nothing:
#[derive(Debug, Clone, Parser)]
struct Args {
/// Comma-delimited log directives to be used for filtering telemetry
#[clap(hide(true), hide_env(false), env = "RUST_LOG")]
rust_log: Option<String>,
}
Is what I'm seeking to do possible at all with latest clap
? I might have to defer to a custom text block otherwise.