git_explore/explore/
cargo.rs

1use super::*;
2
3/// 1. if workspace is directory, push it
4/// 2. if workspace is file, check content, and push it if it exists submodule
5pub fn find_file(opt: &ListOption) -> Result<Vec<PathBuf>> {
6    let files = find_folders(opt.clone()).unwrap();
7
8    let mut paths = Vec::new();
9    files.iter().for_each(|file| {
10        if let crate::FilterKind::File = file.kind {
11            let file_path = file.workspace.join(&opt.filter.name);
12            paths.push(file_path);
13        }
14    });
15
16    Ok(paths)
17}
18
19#[test]
20fn search_git() {
21    use crate::*;
22    use clap::Parser;
23    let cli = RepoCli::parse_from([
24        "git-explore",
25        "list",
26        "-d",
27        KEY_BASEPATH,
28        "-n",
29        "Cargo.toml",
30    ]);
31    // println!("cli: {:#?}", cli);
32    let ret = if let Some(Command::List(opt)) = cli.command {
33        find_file(&opt)
34    } else {
35        todo!()
36    };
37    insta::assert_debug_snapshot!(ret)
38}