summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs42
1 files changed, 25 insertions, 17 deletions
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 @@
1use backup::Backup; 1use backup::Backup;
2use clap::Parser;
3use cli::Subcommands;
2use config::Config; 4use config::Config;
3use packages::{pacman::Pacman, PackageManager}; 5use error::Error;
4use tracing::{debug, info, level_filters::LevelFilter}; 6use tracing::{debug, level_filters::LevelFilter};
5use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; 7use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
6 8
7mod backup; 9mod backup;
10mod cli;
8mod config; 11mod config;
9mod error; 12mod error;
10mod packages; 13mod packages;
@@ -13,7 +16,7 @@ mod pathinfo;
13fn main() -> color_eyre::Result<()> { 16fn main() -> color_eyre::Result<()> {
14 color_eyre::install()?; 17 color_eyre::install()?;
15 18
16 let file_appender = tracing_appender::rolling::never("./", "arps.log"); 19 let file_appender = tracing_appender::rolling::never("./", "arbs.log");
17 let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); 20 let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
18 21
19 tracing_subscriber::registry() 22 tracing_subscriber::registry()
@@ -33,19 +36,24 @@ fn main() -> color_eyre::Result<()> {
33 .init(); 36 .init();
34 debug!("logging initialized"); 37 debug!("logging initialized");
35 38
36 let mut cfg = Config::load()?; 39 let cli = cli::Cli::parse();
37 cfg.user.push("fx".to_string()); 40
38 cfg.directories.push("~/.config/nvim".to_string()); 41 let config = Config::load(cli.config)?;
39 cfg.root = "./backup".to_string(); 42
40 43 match cli.subcommand {
41 let pacman = Pacman; 44 Subcommands::GenerateConfig => Config::generate()?,
42 let pkgs = pacman.get_installed()?; 45 Subcommands::Save { package_manager } => {
43 let backup = Backup::create(&cfg, pkgs); 46 let backup = Backup::create(&config, package_manager)?;
44 // info!(?backup); 47 backup.save(&config)?;
45 // pacman.install(vec![Package { 48 }
46 // id: "lapce".to_string(), 49 Subcommands::Restore => {
47 // version: "0.4.2-1".to_string(), 50 let Some(last_backup) = Backup::get_last(&config)? else {
48 // explicit: true, 51 return Err(Error::BackupNotFound)?;
49 // }])?; 52 };
53
54 last_backup.packages.install()?;
55 last_backup.restore();
56 }
57 };
50 Ok(()) 58 Ok(())
51} 59}