]> git.r.bdr.sh - rbdr/lyricli/blobdiff - src/main.rs
Add pod2man
[rbdr/lyricli] / src / main.rs
index 13b7e37903f13ff278f2165a37718ffbdb6fe19c..d3b3334e44228b1999309a5b9ae9568b0059cf35 100644 (file)
@@ -1,10 +1,11 @@
-// mod configuration;
+mod configuration;
 mod lyrics_engine;
 mod sources;
 
 use std::io::{Result, Error, ErrorKind::Other};
 mod lyrics_engine;
 mod sources;
 
 use std::io::{Result, Error, ErrorKind::Other};
-use clap::{Parser};
+use clap::Parser;
 
 
+use configuration::Configuration;
 use sources::{enable, disable, get_track, reset, list};
 use lyrics_engine::print_lyrics;
 
 use sources::{enable, disable, get_track, reset, list};
 use lyrics_engine::print_lyrics;
 
@@ -45,22 +46,53 @@ pub struct Track {
 
 #[tokio::main]
 async fn main() -> Result<()> {
 
 #[tokio::main]
 async fn main() -> Result<()> {
+    let result = run().await;
+
+    if cfg!(debug_assertions) {
+        result
+    } else {
+        match result {
+            Ok(_) => Ok(()),
+            Err(e) => {
+                eprintln!("Error: {}", e);
+                std::process::exit(1);
+            }
+        }
+    }
+}
+
+async fn run() -> Result<()> {
+    let mut configuration = Configuration::new();
     let arguments = Arguments::parse();
 
     if arguments.list_sources {
     let arguments = Arguments::parse();
 
     if arguments.list_sources {
-        return list();
+        let sources = list();
+        for source in sources {
+            print!("{}", source);
+            if configuration.is_enabled(&source) {
+                print!(" (enabled)");
+            }
+            println!("");
+        }
+        return Ok(());
     }
 
     if let Some(source_name) = arguments.enable_source {
     }
 
     if let Some(source_name) = arguments.enable_source {
-        return enable(source_name);
+        if !configuration.is_enabled(&source_name) {
+            enable(&source_name)?;
+        }
+        return configuration.enable_source(&source_name);
     }
 
     if let Some(source_name) = arguments.disable_source {
     }
 
     if let Some(source_name) = arguments.disable_source {
-        return disable(source_name);
+        if configuration.is_enabled(&source_name) {
+            disable(&source_name)?;
+        }
+        return configuration.disable_source(&source_name);
     }
 
     if let Some(source_name) = arguments.reset_source {
     }
 
     if let Some(source_name) = arguments.reset_source {
-        return reset(source_name);
+        return reset(&source_name);
     }
 
     let current_track: Track;
     }
 
     let current_track: Track;