From 553bbac36bdc483135a7053ca64507e01397e5e1 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 9 Sep 2024 23:03:49 +0200 Subject: add package manager recognition --- src/main.rs | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 1284e0c..7393af9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,13 @@ use backup::Backup; +use clap::Parser; +use cli::Subcommands; use config::Config; -use packages::{pacman::Pacman, PackageManager}; -use tracing::{debug, info, level_filters::LevelFilter}; +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; @@ -13,7 +16,7 @@ mod pathinfo; fn main() -> color_eyre::Result<()> { color_eyre::install()?; - let file_appender = tracing_appender::rolling::never("./", "arps.log"); + let file_appender = tracing_appender::rolling::never("./", "arbs.log"); let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); tracing_subscriber::registry() @@ -33,19 +36,24 @@ fn main() -> color_eyre::Result<()> { .init(); debug!("logging initialized"); - let mut cfg = Config::load()?; - cfg.user.push("fx".to_string()); - cfg.directories.push("~/.config/nvim".to_string()); - cfg.root = "./backup".to_string(); - - let pacman = Pacman; - let pkgs = pacman.get_installed()?; - let backup = Backup::create(&cfg, pkgs); - // info!(?backup); - // pacman.install(vec![Package { - // id: "lapce".to_string(), - // version: "0.4.2-1".to_string(), - // explicit: true, - // }])?; + 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 => { + let Some(last_backup) = Backup::get_last(&config)? else { + return Err(Error::BackupNotFound)?; + }; + + last_backup.packages.install()?; + last_backup.restore(); + } + }; Ok(()) } -- cgit v1.2.3