]> git.r.bdr.sh - rbdr/lyricli/blobdiff - src/main.rs
Add macos sources
[rbdr/lyricli] / src / main.rs
index 13b7e37903f13ff278f2165a37718ffbdb6fe19c..a6119266f25581e98b17ff7530816455372b4d2e 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,37 @@ pub struct Track {
 
 #[tokio::main]
 async fn main() -> Result<()> {
 
 #[tokio::main]
 async fn main() -> 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;