clap/tests
bors[bot] 1e7c9efc9d
Merge #1612
1612: Use about() with help() and long_about() with long_help() r=pksunkara a=TheLostLambda

I was going through the clap documentation and was under the impression that calling `help()` would call `about()` and `long_help()` would call `long_about()`, but I've actually discovered this not to be the case. Instead, the `long_about()` was always shown when it existed, rendering the output (in the about section) of programs called with `-h` and `--help` identical. Issue #1472 shows this and that is fixed here.

Note this doesn't remove the ability to use the same about in both cases: if `long_about()` is unset, then `about()` is used in both cases.

I've changed the implementation here to use `is_some()` and `unwrap()` as opposed to `if let` because it ultimately allows for less repetitive code. Ideally, I'd be able to pair `if let` with a secondary condition (namely `self.use_long`), but to my dismay, let-chains are not stabilized yet.

For a second opinion, here is the code a settled on:
```
if self.use_long && parser.meta.long_about.is_some() {
    debugln!("Help::write_default_help: writing long about");
    write_thing!(parser.meta.long_about.unwrap())
} else if parser.meta.about.is_some() {
    debugln!("Help::write_default_help: writing about");
    write_thing!(parser.meta.about.unwrap())
}
```
Here is the alternative:
```
if self.use_long {
    if let Some(about) = parser.meta.long_about {
        debugln!("Help::write_default_help: writing long about");
        write_thing!(about)
    } else if let Some(about) = parser.meta.about {
        debugln!("Help::write_default_help: writing about");
        write_thing!(about)
   }
} else {
    if let Some(about) = parser.meta.about {
        debugln!("Help::write_default_help: writing about");
        write_thing!(about)
    }
}
```

Co-authored-by: Brooks J Rady <b.j.rady@gmail.com>
2020-02-13 07:21:05 +00:00
..
fixtures Put the test helper in tests 2020-02-04 09:51:46 +01:00
app_from_crate.rs Use 'Clap Maintainers' as authors 2020-02-10 20:16:25 +01:00
app_settings.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
arg_aliases.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
borrowed.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
cargo.rs Use 'Clap Maintainers' as authors 2020-02-10 20:16:25 +01:00
conflicts.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
default_vals.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
delimiters.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
derive_order.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
env.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
flags.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
global_args.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
groups.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
help.rs Merge #1612 2020-02-13 07:21:05 +00:00
hidden_args.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
indices.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
macros.rs Remove #[macro_use] from tests 2020-02-03 12:01:36 -05:00
multiple_occurrences.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
multiple_values.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
opts.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
positionals.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
posix_compatible.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
possible_values.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
propagate_globals.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
require.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
subcommands.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
template_help.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
tests.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
unique_args.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
utf8.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
utils.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
version-numbers.rs Remove #[macro_use] from tests 2020-02-03 12:01:36 -05:00
version.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00
yaml.rs Put the test helper in tests 2020-02-04 09:51:46 +01:00