-
Notifications
You must be signed in to change notification settings - Fork 11
/
lib.rs
38 lines (34 loc) · 1.02 KB
/
lib.rs
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
use std::process::{Command, Output};
pub struct CodebaseFiles {
pub paths: Vec<String>,
}
impl CodebaseFiles {
pub fn all() -> CodebaseFiles {
let output = Command::new("git").arg("ls-files").output();
let mut paths = Self::process_ls_files(output);
paths.extend(Self::process_ls_files(
Command::new("git")
.arg("ls-files")
.arg("--others")
.arg("--exclude-standard")
.output(),
));
paths.sort();
paths.dedup();
CodebaseFiles { paths }
}
fn process_ls_files<T>(output: Result<Output, T>) -> Vec<String> {
match output {
Ok(o) => {
if o.status.success() {
std::str::from_utf8(&o.stdout).map_or(vec![], |v| {
v.lines().map(|k| k.to_string()).collect::<Vec<String>>()
})
} else {
vec![]
}
}
_ => vec![],
}
}
}