tool_sync/
lib.rs

1mod config;
2mod infra;
3mod install;
4mod model;
5mod sync;
6
7use clap::Parser;
8use std::path::PathBuf;
9
10use crate::config::cli::{Cli, Command};
11use crate::infra::err;
12
13pub fn run() {
14    let cli = Cli::parse();
15
16    // TODO: this is redundant for the `default-config` command
17    // See: https://github.com/chshersh/tool-sync/issues/75
18    let config_path = resolve_config_path(cli.config);
19
20    match cli.command {
21        Command::DefaultConfig => config::template::generate_default_config(),
22        Command::Sync => sync::sync_from_path(config_path),
23        Command::Install { name } => install::install(config_path, name),
24    }
25}
26
27const DEFAULT_CONFIG_PATH: &str = ".tool.toml";
28
29fn resolve_config_path(config_path: Option<PathBuf>) -> PathBuf {
30    match config_path {
31        Some(path) => path,
32        None => match dirs::home_dir() {
33            Some(home_path) => {
34                let mut path = PathBuf::new();
35                path.push(home_path);
36                path.push(DEFAULT_CONFIG_PATH);
37                path
38            }
39            None => {
40                err::abort_suggest_issue("Unable to find $HOME directory");
41            }
42        },
43    }
44}