summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs47
1 files changed, 39 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 487d095..ab23ab7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,8 +2,9 @@ use backup::Backup;
2use clap::Parser; 2use clap::Parser;
3use cli::Subcommands; 3use cli::Subcommands;
4use config::Config; 4use config::Config;
5use error::Error; 5use error::{Error, Result};
6use tracing::{debug, level_filters::LevelFilter}; 6use notify_rust::Urgency;
7use tracing::{debug, error, level_filters::LevelFilter};
7use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; 8use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
8 9
9mod backup; 10mod backup;
@@ -13,9 +14,7 @@ mod error;
13mod packages; 14mod packages;
14mod pathinfo; 15mod pathinfo;
15 16
16fn main() -> color_eyre::Result<()> { 17fn main() -> Result<()> {
17 color_eyre::install()?;
18
19 let file_appender = tracing_appender::rolling::never("./", "arbs.log"); 18 let file_appender = tracing_appender::rolling::never("./", "arbs.log");
20 let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); 19 let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
21 20
@@ -35,15 +34,27 @@ fn main() -> color_eyre::Result<()> {
35 ) 34 )
36 .init(); 35 .init();
37 debug!("logging initialized"); 36 debug!("logging initialized");
37
38 match run_cli() {
39 Ok(()) => { println!("OK") ; Ok(())},
40 Err(err) => {
41 error!(?err);
42 error!("{:?}", std::error::Error::source(&err));
43 send_notification("Backup Error", &err.to_string(), Urgency::Critical)?;
44 Err(err)
45 }
46 }
47}
38 48
49fn run_cli() -> Result<()> {
39 let cli = cli::Cli::parse(); 50 let cli = cli::Cli::parse();
40 51
41 let config = Config::load(cli.config)?; 52 let config = Config::load(cli.config)?;
42 53
43 match cli.subcommand { 54 match cli.subcommand {
44 Subcommands::GenerateConfig => Config::generate()?, 55 Subcommands::GenerateConfig => Config::generate()?,
45 Subcommands::Save { package_manager } => { 56 Subcommands::Save => {
46 let backup = Backup::create(&config, package_manager)?; 57 let backup = Backup::create(&config)?;
47 backup.save(&config)?; 58 backup.save(&config)?;
48 } 59 }
49 Subcommands::Restore { package_install } => { 60 Subcommands::Restore { package_install } => {
@@ -56,7 +67,27 @@ fn main() -> color_eyre::Result<()> {
56 } 67 }
57 68
58 last_backup.restore(&config)?; 69 last_backup.restore(&config)?;
59 } 70 },
60 }; 71 };
61 Ok(()) 72 Ok(())
62} 73}
74
75fn send_notification(summary: &str, body: &str, urgency: Urgency) -> Result<()> {
76 #[cfg(feature = "notifications")]
77 {
78 let Some(mut icon) = dirs::data_dir() else {
79 return Err(Error::NoSysDir);
80 };
81 icon.push(env!("CARGO_PKG_NAME"));
82 icon.push("icon.png");
83
84 notify_rust::Notification::new()
85 .summary(summary)
86 .body(body)
87 .icon(&icon.to_string_lossy())
88 .timeout(0)
89 .urgency(urgency)
90 .show()?;
91 }
92 Ok(())
93}