Merge pull request #2470 from ldm0/master

Add multiple_* parsing for yaml
This commit is contained in:
Pavan Kumar Sunkara 2021-05-07 12:26:59 +01:00 committed by GitHub
commit df69011025
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 1 deletions

View file

@ -7,8 +7,8 @@ use std::ops::{Deref, DerefMut};
/// An entity with a span attached.
#[derive(Debug, Clone)]
pub struct Sp<T> {
span: Span,
val: T,
span: Span,
}
impl<T> Sp<T> {

View file

@ -4654,6 +4654,8 @@ impl<'help> From<&'help Yaml> for Arg<'help> {
"index" => yaml_to_usize!(a, v, index),
"global" => yaml_to_bool!(a, v, global),
"multiple" => yaml_to_bool!(a, v, multiple),
"multiple_occurrences" => yaml_to_bool!(a, v, multiple_occurrences),
"multiple_values" => yaml_to_bool!(a, v, multiple_values),
"hidden" => yaml_to_bool!(a, v, hidden),
"next_line_help" => yaml_to_bool!(a, v, next_line_help),
"group" => yaml_to_str!(a, v, group),

View file

@ -79,6 +79,10 @@ args:
multiple: true
use_delimiter: true
require_delimiter: true
- settings:
short: s
takes_value: true
multiple_values: true
- singlealias:
long: singlealias
about: Tests single alias
@ -122,6 +126,11 @@ args:
long: value-hint
help: Test value_hint
value_hint: FilePath
- verbose:
short: v
multiple_occurrences: true
takes_value: false
help: Sets the level of verbosity
- visiblealiases:
long: visiblealiases
about: Tests visible aliases

View file

@ -100,6 +100,24 @@ fn default_value_if_triggered_by_flag_and_argument() {
assert_eq!(matches.value_of("positional2").unwrap(), "some");
}
#[test]
fn yaml_multiple_occurrences() {
let yaml = load_yaml!("fixtures/app.yaml");
let matches = App::from(yaml)
.try_get_matches_from(vec!["prog", "-vvv"])
.unwrap();
assert_eq!(matches.occurrences_of("verbose"), 3);
}
#[test]
fn yaml_multiple_values() {
let yaml = load_yaml!("fixtures/app.yaml");
let matches = App::from(yaml)
.try_get_matches_from(vec!["prog", "-s", "aaa", "bbb"])
.unwrap();
assert_eq!(matches.values_of("settings").unwrap().collect::<Vec<&str>>(), vec!["aaa", "bbb"]);
}
#[cfg(feature = "regex")]
#[test]
fn regex_with_invalid_string() {