X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli/blobdiff_plain/738ec06d26a2a19bdda8a992d2250e731d954631..6371abaa3ffda8eed22eee5df5f61a9f44cfad61:/src/main.rs?ds=inline diff --git a/src/main.rs b/src/main.rs index 13b7e37..d3b3334 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,53 @@ pub struct Track { #[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 { - 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;