Skip to main content

affected/
lib.rs

1mod config;
2pub mod graph;
3pub mod logger;
4mod node;
5pub mod nx;
6mod projects;
7pub mod tasks;
8pub mod workspace;
9
10use anyhow::Result;
11use clap::ValueEnum;
12pub use config::Config;
13use std::collections::HashSet;
14use std::path::{Path, PathBuf};
15
16#[derive(ValueEnum, Clone, Debug)]
17pub enum OutputFormat {
18    Json,
19    Text,
20}
21
22pub fn print_lines(lines: &HashSet<String>, format: &OutputFormat) -> Result<()> {
23    match format {
24        OutputFormat::Json => {
25            let json_output = serde_json::to_string_pretty(&lines)?;
26            println!("{}", json_output);
27        }
28        _ => {
29            for line in lines {
30                println!("{}", line);
31            }
32        }
33    }
34    Ok(())
35}
36
37pub fn find_git_root(starting_dir: &Path) -> Option<PathBuf> {
38    let mut current_dir = starting_dir;
39
40    while current_dir != current_dir.parent()? {
41        if current_dir.join(".git").exists() {
42            return Some(current_dir.to_path_buf());
43        }
44        current_dir = current_dir.parent()?;
45    }
46
47    None
48}