use backup::Backup; use clap::Parser; use cli::Subcommands; use config::Config; use error::Error; use tracing::{debug, level_filters::LevelFilter}; use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; mod backup; mod cli; mod config; mod error; mod packages; mod pathinfo; fn main() -> color_eyre::Result<()> { color_eyre::install()?; let file_appender = tracing_appender::rolling::never("./", "arbs.log"); let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); tracing_subscriber::registry() .with( fmt::layer() .with_writer(non_blocking) .with_file(false) .with_ansi(false) .without_time(), ) .with(fmt::layer().with_file(false).without_time()) .with( EnvFilter::builder() .with_default_directive(LevelFilter::INFO.into()) .from_env_lossy(), ) .init(); debug!("logging initialized"); let cli = cli::Cli::parse(); let config = Config::load(cli.config)?; match cli.subcommand { Subcommands::GenerateConfig => Config::generate()?, Subcommands::Save { package_manager } => { let backup = Backup::create(&config, package_manager)?; backup.save(&config)?; } Subcommands::Restore { package_install } => { let Some(last_backup) = Backup::get_last(&config)? else { return Err(Error::BackupNotFound)?; }; if package_install { last_backup.packages.install()?; } last_backup.restore(&config)?; } }; Ok(()) }