Show env option in CLI reference documentation (#6863)

## Summary

Closes #6469.

<img width="721" alt="image"
src="https://github.com/user-attachments/assets/be144e43-e02f-473e-921c-91cf00c3c8d3">
This commit is contained in:
eth3lbert 2024-09-04 01:10:49 +08:00 committed by GitHub
parent becdd4bdaf
commit c667588524
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 417 additions and 0 deletions

View file

@ -245,6 +245,7 @@ fn generate_command<'a>(output: &mut String, command: &'a Command, parents: &mut
if let Some(help) = opt.get_long_help().or_else(|| opt.get_help()) {
output.push_str("<dd>");
output.push_str(&format!("{}\n", markdown::to_html(&help.to_string())));
emit_env_option(opt, output);
emit_default_option(opt, output);
emit_possible_options(opt, output);
output.push_str("</dd>");
@ -267,6 +268,18 @@ fn generate_command<'a>(output: &mut String, command: &'a Command, parents: &mut
parents.pop();
}
fn emit_env_option(opt: &clap::Arg, output: &mut String) {
if opt.is_hide_env_set() {
return;
}
if let Some(env) = opt.get_env() {
output.push_str(&markdown::to_html(&format!(
"May also be set with the `{}` environment variable.",
env.to_string_lossy()
)));
}
}
fn emit_default_option(opt: &clap::Arg, output: &mut String) {
if opt.is_hide_default_value_set() || !opt.get_num_args().expect("built").takes_values() {
return;