-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues 546,549 #551
Merged
Merged
Issues 546,549 #551
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…al delimiter to parse multiple values Using this setting requires a value delimiter be present in order to parse multiple values. Otherwise it is assumed no values follow, and moves on to the next arg with a clean slate. These examples demonstrate what happens when `require_delimiter(true)` is used. Notice everything works in this first example, as we use a delimiter, as expected. ```rust let delims = App::new("reqdelims") .arg(Arg::with_name("opt") .short("o") .takes_value(true) .multiple(true) .require_delimiter(true)) // Simulate "$ reqdelims -o val1,val2,val3" .get_matches_from(vec![ "reqdelims", "-o", "val1,val2,val3", ]); assert!(delims.is_present("opt")); assert_eq!(delims.values_of("opt").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]); ``` In this next example, we will *not* use a delimiter. Notice it's now an error. ```rust let res = App::new("reqdelims") .arg(Arg::with_name("opt") .short("o") .takes_value(true) .multiple(true) .require_delimiter(true)) // Simulate "$ reqdelims -o val1 val2 val3" .get_matches_from_safe(vec![ "reqdelims", "-o", "val1", "val2", "val3", ]); assert!(res.is_err()); let err = res.unwrap_err(); assert_eq!(err.kind, ErrorKind::UnknownArgument); ``` What's happening is `-o` is getting `val1`, and because delimiters are required yet none were present, it stops parsing `-o`. At this point it reaches `val2` and because no positional arguments have been defined, it's an error of an unexpected argument. In this final example, we contrast the above with `clap`'s default behavior where the above is *not* an error. ```rust let delims = App::new("reqdelims") .arg(Arg::with_name("opt") .short("o") .takes_value(true) .multiple(true)) // Simulate "$ reqdelims -o val1 val2 val3" .get_matches_from(vec![ "reqdelims", "-o", "val1", "val2", "val3", ]); assert!(delims.is_present("opt")); assert_eq!(delims.values_of("opt").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]); ```
…ll in just that portion The functionality can now be found in https://crates.io/crates/term_size Closes #549
r? @sru (yo-bot has picked a reviewer for you, use r? to override) |
@homu r+ |
📌 Commit e5ba93a has been approved by |
☀️ Test successful - status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.