Skip to content

Commit 0645344

Browse files
committed
docs: document grouped_values_of
Relates to clap-rs#2924
1 parent 9e3b661 commit 0645344

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/parse/matches/arg_matches.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,39 @@ impl ArgMatches {
293293
Some(v)
294294
}
295295

296-
/// Placeholder documentation.
296+
/// Get an [`Iterator`] over groups of values of a specific option.
297+
///
298+
/// specifically grouped by the occurrences of the options.
299+
///
300+
/// Each group is a `Vec<&str>` containing the arguments passed to a single occurrence
301+
/// of the option.
302+
///
303+
/// If the option doesn't support multiple occurrences, or there was only a single occurrence,
304+
/// the iterator will only contain a single item.
305+
///
306+
/// Returns `None` if the option wasn't present.
307+
///
308+
/// # Panics
309+
///
310+
/// If the value is invalid UTF-8.
311+
///
312+
/// If `id` is not a valid argument or group name.
313+
///
314+
/// # Examples
315+
/// ```rust
316+
/// # use clap::{Command,Arg};
317+
/// let m = Command::new("myprog")
318+
/// .arg(Arg::new("exec")
319+
/// .short('x')
320+
/// .min_values(1)
321+
/// .multiple_occurrences(true)
322+
/// .value_terminator(";"))
323+
/// .get_matches_from(vec![
324+
/// "myprog", "-x", "echo", "hi", ";", "-x", "echo", "bye"]);
325+
/// let vals: Vec<Vec<&str>> = m.grouped_values_of("exec").unwrap().collect();
326+
/// assert_eq!(vals, [["echo", "hi"], ["echo", "bye"]]);
327+
/// ```
328+
/// [`Iterator`]: std::iter::Iterator
297329
#[cfg(feature = "unstable-grouped")]
298330
#[cfg_attr(debug_assertions, track_caller)]
299331
pub fn grouped_values_of<T: Key>(&self, id: T) -> Option<GroupedValues> {

0 commit comments

Comments
 (0)