Skip to content

Commit

Permalink
Do not print true, false options for flags
Browse files Browse the repository at this point in the history
The user cannot write `--list false` for a flag.

Fixes ConnorGray#19.
  • Loading branch information
ilyagr committed Jun 13, 2024
1 parent 31d651c commit d3985a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
3 changes: 0 additions & 3 deletions docs/examples/complex-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ does testing things

* `-l`, `--list` — lists test values

Possible values: `true`, `false`




<hr/>
Expand Down
27 changes: 11 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn write_help_markdown(
// build_table_of_contents_html(buffer, Vec::new(), command, 0).unwrap();
// writeln!(buffer, "</ul></div>").unwrap();

if ! options.disable_toc {
if !options.disable_toc {
writeln!(buffer, "**Command Overview:**\n").unwrap();

build_table_of_contents_markdown(buffer, Vec::new(), command, 0)
Expand Down Expand Up @@ -261,11 +261,7 @@ fn build_command_markdown(
}
*/

writeln!(
buffer,
"## `{}`\n",
command_path.join(" "),
)?;
writeln!(buffer, "## `{}`\n", command_path.join(" "),)?;

if let Some(long_about) = command.get_long_about() {
writeln!(buffer, "{}\n", long_about)?;
Expand Down Expand Up @@ -316,15 +312,12 @@ fn build_command_markdown(

let title_name = get_canonical_name(subcommand);

writeln!(
buffer,
"* `{}` — {}",
title_name,
match subcommand.get_about() {
Some(about) => about.to_string(),
None => String::new(),
}
)?;
writeln!(buffer, "* `{}` — {}", title_name, match subcommand
.get_about()
{
Some(about) => about.to_string(),
None => String::new(),
})?;
}

writeln!(buffer)?;
Expand Down Expand Up @@ -462,7 +455,9 @@ fn write_arg_markdown(buffer: &mut String, arg: &clap::Arg) -> fmt::Result {
.filter(|pv| !pv.is_hide_set())
.collect();

if !possible_values.is_empty() {
if !matches!(arg.get_action(), clap::ArgAction::SetTrue)
&& !possible_values.is_empty()
{
let any_have_help: bool =
possible_values.iter().any(|pv| pv.get_help().is_some());

Expand Down

0 comments on commit d3985a3

Please sign in to comment.