1pub mod git;
2pub mod ignore;
3pub mod output;
4pub mod scorer;
5pub mod session;
6
7pub use git::{ls_files, repo_root};
8pub use ignore::IgnorePatterns;
9pub use output::{CatOutput, FileOutput, OutputFormat, TreeOutput};
10pub use scorer::{score_file, score_files, ScoredFile};
11pub use session::Session;
12
13use std::path::Path;
14
15pub fn get_context(
16 root: &Path,
17 min_score: i32,
18) -> Result<Vec<ScoredFile>, Box<dyn std::error::Error>> {
19 let files = ls_files(root)?;
20 let ignore = IgnorePatterns::load(root);
21
22 let file_strs: Vec<String> = files
23 .into_iter()
24 .filter_map(|p| p.to_str().map(String::from))
25 .filter(|p| !ignore.is_ignored(p))
26 .collect();
27
28 let mut scored = score_files(file_strs);
29 scored.retain(|f| f.score >= min_score);
30 scored.sort_by(|a, b| b.score.cmp(&a.score).then(a.path.cmp(&b.path)));
31
32 Ok(scored)
33}