Skip to content

Commit

Permalink
Merge pull request #4348 from mattmadeofpasta/clarify_no_long_help_te…
Browse files Browse the repository at this point in the history
…xt_for_possiblevalue

Clarify that the "body" part of the doc comment on a `ValueEnum` is ignored
  • Loading branch information
epage committed Oct 4, 2022
2 parents 39fe46e + e644a5e commit 9c21794
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
22 changes: 21 additions & 1 deletion examples/tutorial_builder/04_01_enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@ A simple to use, efficient, and full-featured Command Line Argument Parser

Usage: 04_01_enum[EXE] <MODE>

Arguments:
<MODE>
What mode to run the program in

Possible values:
- fast: Run swiftly
- slow: Crawl slowly but steadily

Options:
-h, --help
Print help information (use `-h` for a summary)

-V, --version
Print version information

$ 04_01_enum -h
A simple to use, efficient, and full-featured Command Line Argument Parser

Usage: 04_01_enum[EXE] <MODE>

Arguments:
<MODE> What mode to run the program in [possible values: fast, slow]

Options:
-h, --help Print help information
-h, --help Print help information (use `--help` for more detail)
-V, --version Print version information

$ 04_01_enum fast
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial_builder/04_01_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ impl ValueEnum for Mode {

fn to_possible_value<'a>(&self) -> Option<PossibleValue> {
Some(match self {
Mode::Fast => PossibleValue::new("fast"),
Mode::Slow => PossibleValue::new("slow"),
Mode::Fast => PossibleValue::new("fast").help("Run swiftly"),
Mode::Slow => PossibleValue::new("slow").help("Crawl slowly but steadily"),
})
}
}
Expand Down
22 changes: 21 additions & 1 deletion examples/tutorial_derive/04_01_enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,31 @@ A simple to use, efficient, and full-featured Command Line Argument Parser

Usage: 04_01_enum_derive[EXE] <MODE>

Arguments:
<MODE>
What mode to run the program in

Possible values:
- fast: Run swiftly
- slow: Crawl slowly but steadily

Options:
-h, --help
Print help information (use `-h` for a summary)

-V, --version
Print version information

$ 04_01_enum_derive -h
A simple to use, efficient, and full-featured Command Line Argument Parser

Usage: 04_01_enum_derive[EXE] <MODE>

Arguments:
<MODE> What mode to run the program in [possible values: fast, slow]

Options:
-h, --help Print help information
-h, --help Print help information (use `--help` for more detail)
-V, --version Print version information

$ 04_01_enum_derive fast
Expand Down
4 changes: 4 additions & 0 deletions examples/tutorial_derive/04_01_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ struct Cli {

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
enum Mode {
/// Run swiftly
Fast,
/// Crawl slowly but steadily
///
/// This paragraph is ignored because there is no long help text for possible values.
Slow,
}

Expand Down
20 changes: 16 additions & 4 deletions tests/derive/doc_comments_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,26 @@ fn multiline_separates_default() {
}

#[test]
fn argenum_multiline_doc_comment() {
#[derive(ValueEnum, Clone)]
fn value_enum_multiline_doc_comment() {
#[derive(Parser, Debug)]
struct Command {
x: LoremIpsum,
}

#[derive(ValueEnum, Clone, PartialEq, Debug)]
enum LoremIpsum {
/// Multiline
/// Doc comment summary
///
/// Doc comment
/// The doc comment body is ignored
Bar,
}

let help = utils::get_long_help::<Command>();

assert!(help.contains("Doc comment summary"));

// There is no long help text for possible values. The long help only contains the summary.
assert!(!help.contains("The doc comment body is ignored"));
}

#[test]
Expand Down

0 comments on commit 9c21794

Please sign in to comment.