X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli/blobdiff_plain/b2096fb3958d9e9cdcca77931aadfb947cab24ee..44e7b4de4073e6dc25681bb2fa6977bf5869689a:/src/main.rs?ds=inline diff --git a/src/main.rs b/src/main.rs index 13b7e37..a611926 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,11 @@ -// mod configuration; +mod configuration; 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; @@ -45,22 +46,37 @@ pub struct Track { #[tokio::main] async fn main() -> Result<()> { + let mut configuration = Configuration::new(); 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 { - 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 { - 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 { - return reset(source_name); + return reset(&source_name); } let current_track: Track;