use std::{ env::set_current_dir, fs::{exists, read_to_string, File}, path::{absolute, Path}, process::{exit, Stdio}, }; use action::Action; use cfg::Config; use clap::Parser; use colored::Colorize; use execute::{command_args, Execute}; use log::{debug, error, info, trace, warn}; use prelude::abspath; mod action; mod cfg; mod crates; mod logging; mod prelude; mod source; fn main() -> Result<(), Box> { logging::setup_logger()?; let git_sha1 = String::from_utf8( command_args!("git", "rev-parse", "HEAD") .stdout(Stdio::piped()) .execute_output()? .stdout, )?; let action = Action::parse(); match action { Action::Sync { config_path } => { trace!("fetching config dir... {config_path:?}"); if let Some(config_path) = abspath(&config_path.unwrap_or("~/.syncr".into())) { trace!("setting config dir as cwd... {config_path}"); set_current_dir(config_path)?; } let config = toml::from_str::(&read_to_string(abspath("./syncr.toml").unwrap())?)?; info!("syncing \"{}\"...", config.title.bold()); info!("updating sources..."); let mut available_sources = vec![]; for (name, source) in &config.source { debug!("checking {name}..."); if !source.available() { warn!("source \"{name}\" unavailable."); } else { info!("source \"{name}\" available!"); available_sources.push(source); } } if available_sources.len() == 0 { error!("{}", "sync impossible; no sources.".bold()); exit(1); } let oldpwd = absolute(".")?; for source in available_sources { // cd to source dir source.go_to_dir()?; for c in source.get_crates()? { info!("{} pkgs", c.pkgs.len()) } } } _ => { println!("{action:#?}"); } } Ok(()) }