5 use std::io::{Result, Error, ErrorKind::Other};
8 use configuration::Configuration;
9 use sources::{enable, disable, get_track, reset, list};
10 use lyrics_engine::print_lyrics;
12 #[derive(Parser, Debug)]
13 #[command(version, about, long_about = None)]
16 // Positional Arguments
17 /// Specify the artist.
18 artist: Option<String>,
20 /// Specify the artist.
21 track_name: Option<String>,
23 /// Show title of track if present
24 #[arg(short = 't', long)]
32 #[arg(short, long, value_name = "SOURCE")]
33 enable_source: Option<String>,
35 #[arg(short, long, value_name = "SOURCE")]
36 disable_source: Option<String>,
38 #[arg(short, long, value_name = "SOURCE")]
39 reset_source: Option<String>,
48 async fn main() -> Result<()> {
49 let mut configuration = Configuration::new();
50 let arguments = Arguments::parse();
52 if arguments.list_sources {
54 for source in sources {
56 if configuration.is_enabled(&source) {
64 if let Some(source_name) = arguments.enable_source {
65 if !configuration.is_enabled(&source_name) {
66 enable(&source_name)?;
68 return configuration.enable_source(&source_name);
71 if let Some(source_name) = arguments.disable_source {
72 if configuration.is_enabled(&source_name) {
73 disable(&source_name)?;
75 return configuration.disable_source(&source_name);
78 if let Some(source_name) = arguments.reset_source {
79 return reset(&source_name);
82 let current_track: Track;
83 if let Some(artist) = arguments.artist {
84 current_track = Track {
85 name: arguments.track_name.unwrap_or("".to_string()),
89 current_track = get_track()
90 .ok_or_else(|| Error::new(Other, "No Artist/Song could be found :("))?
93 print_lyrics(current_track, arguments.show_title).await