cargo_e/
e_parser.rs

1/// Parses the stderr output to extract available items (e.g. binaries or examples)
2/// by looking for a marker of the form "Available {item}:".
3///
4/// # Example
5/// ```
6/// use cargo_e::e_parser::parse_available;
7///
8/// let stderr = "Available examples:\n  example1\n  example2\n";
9/// let result = parse_available(stderr, "examples");
10/// assert_eq!(result, vec!["example1", "example2"]);
11/// ```
12pub fn parse_available(stderr: &str, item: &str) -> Vec<String> {
13    let marker = format!("Available {}:", item);
14    let mut available = Vec::new();
15    let mut collecting = false;
16
17    for line in stderr.lines() {
18        if collecting {
19            let trimmed = line.trim();
20            if !trimmed.is_empty() {
21                available.push(trimmed.to_string());
22            }
23        }
24        if line.contains(&marker) {
25            collecting = true;
26        }
27    }
28    available
29}