summaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: c682def7e75517768fea010423906bbad7ea18cc (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
use anyhow::{Context, Result};
use clap::Parser;
use figment::providers::{Env, Format, Toml};
use tmuxr::{Cli, Config, Finder, Logging, Paths};
use tracing::info;

fn main() -> Result<()> {
    let config = Config::figment()
        .merge(Cli::parse())
        .merge(Toml::file("tmuxr.toml"))
        .merge(Env::prefixed("TMUXR_"))
        .extract()
        .context("Failed to extract config")?;

    Logging::from_provider(&config)
        .context("Failed to extract logging config")?
        .init()
        .context("Failed to initialize logging")?;

    run(&config)
}

#[tracing::instrument]
pub fn run(config: &Config) -> Result<()> {
    let paths = Paths::from_provider(config).context("Failed to extract paths config")?;
    let selected = Finder::from_provider(config)
        .context("Failed to extract finder config")?
        .spawn()
        .context("Failed to spawn finder process")?
        .find(paths)
        .context("Failed to write paths to finder stdin")?;

    info!("{:?}", selected);

    Ok(())
}