aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 103101b29e9856124fe46b17f55fc4313f67d83a (plain)
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
use std::str::FromStr;

use anyhow::Result;
use clap::Parser;
use projectr::{config::Config, project::Projects, tmux::Tmux, Search};
use tracing::metadata::LevelFilter;

fn main() -> Result<()> {
    let config = Config::parse();

    tracing_subscriber::fmt::fmt()
        .pretty()
        .with_writer(std::io::stderr)
        .with_max_level(LevelFilter::from_str(&config.verbosity.to_string())?)
        .init();

    let mut projects = Projects::from(config.parsers);

    projects.extend(config.include);

    // Workaround due to ignore::WalkBuilder not implementing Default.
    if let Some((init, paths)) = config.search.paths.split_first() {
        let mut search = Search::new(init);

        for path in paths {
            search.add(path);
        }

        search.max_depth(config.search.max_depth);
        search.hidden(!config.search.hidden);

        projects.extend(search);
    }

    if config.tmux_sessions {
        if let Ok(sessions) = Tmux::sessions() {
            projects.extend(sessions)
        }
    }

    Ok(projects.write(std::io::stdout())?)
}