Support loading help_message and version_message from the YAML

This commit is contained in:
Caleb Jones 2017-03-10 01:52:02 -05:00
parent 389c413b70
commit c5dac3fa43
3 changed files with 17 additions and 0 deletions

View file

@ -1467,6 +1467,8 @@ impl<'a> From<&'a Yaml> for App<'a, 'a> {
yaml_str!(a, yaml, help); yaml_str!(a, yaml, help);
yaml_str!(a, yaml, help_short); yaml_str!(a, yaml, help_short);
yaml_str!(a, yaml, version_short); yaml_str!(a, yaml, version_short);
yaml_str!(a, yaml, help_message);
yaml_str!(a, yaml, version_message);
yaml_str!(a, yaml, alias); yaml_str!(a, yaml, alias);
yaml_str!(a, yaml, visible_alias); yaml_str!(a, yaml, visible_alias);

View file

@ -4,6 +4,7 @@ about: tests clap library
author: Kevin K. <kbknapp@gmail.com> author: Kevin K. <kbknapp@gmail.com>
settings: settings:
- ArgRequiredElseHelp - ArgRequiredElseHelp
help_message: prints help with a nonstandard description
args: args:
- opt: - opt:
short: o short: o

View file

@ -10,3 +10,17 @@ fn create_app_from_yaml() {
let yml = load_yaml!("app.yml"); let yml = load_yaml!("app.yml");
App::from_yaml(yml); App::from_yaml(yml);
} }
#[test]
fn help_message() {
let yml = load_yaml!("app.yml");
let mut app = App::from_yaml(yml);
// Generate the full help message!
let _ = app.get_matches_from_safe_borrow(Vec::<String>::new());
let mut help_buffer = Vec::new();
app.write_help(&mut help_buffer).unwrap();
let help_string = String::from_utf8(help_buffer).unwrap();
assert!(help_string.contains(
"-h, --help prints help with a nonstandard description\n"));
}