1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/// Parses the stderr output to extract available items (e.g. binaries or examples)
/// by looking for a marker of the form "Available {item}:".
///
/// # Example
/// ```
/// use cargo_e::e_parser::parse_available;
///
/// let stderr = "Available examples:\n example1\n example2\n";
/// let result = parse_available(stderr, "examples");
/// assert_eq!(result, vec!["example1", "example2"]);
/// ```
pub fn parse_available(stderr: &str, item: &str) -> Vec<String> {
let marker = format!("Available {}:", item);
let mut available = Vec::new();
let mut collecting = false;
for line in stderr.lines() {
if collecting {
let trimmed = line.trim();
if !trimmed.is_empty() {
available.push(trimmed.to_string());
}
}
if line.to_lowercase().contains(&marker.to_lowercase()) {
collecting = true;
}
}
available
}
/// Reads run history from a file and returns a HashMap mapping target names to run counts.
pub fn read_run_history(
history_path: &std::path::Path,
) -> std::collections::HashMap<String, usize> {
let mut history = std::collections::HashMap::new();
if let Ok(contents) = std::fs::read_to_string(history_path) {
for line in contents.lines() {
let trimmed = line.trim();
if !trimmed.is_empty() {
// Increment the count for this target.
*history.entry(trimmed.to_string()).or_insert(0) += 1;
}
}
}
history
}