mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Merge pull request #2470 from ldm0/master
Add multiple_* parsing for yaml
This commit is contained in:
commit
df69011025
4 changed files with 30 additions and 1 deletions
|
@ -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> {
|
||||
|
|
|
@ -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),
|
||||
|
|
9
tests/fixtures/app.yaml
vendored
9
tests/fixtures/app.yaml
vendored
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue