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 result = run().await;
51 if cfg!(debug_assertions) {
57 eprintln!("Error: {}", e);
58 std::process::exit(1);
64 async fn run() -> Result<()> {
65 let mut configuration = Configuration::new();
66 let arguments = Arguments::parse();
68 if arguments.list_sources {
70 for source in sources {
72 if configuration.is_enabled(&source) {
80 if let Some(source_name) = arguments.enable_source {
81 if !configuration.is_enabled(&source_name) {
82 enable(&source_name)?;
84 return configuration.enable_source(&source_name);
87 if let Some(source_name) = arguments.disable_source {
88 if configuration.is_enabled(&source_name) {
89 disable(&source_name)?;
91 return configuration.disable_source(&source_name);
94 if let Some(source_name) = arguments.reset_source {
95 return reset(&source_name);
98 let current_track: Track;
99 if let Some(artist) = arguments.artist {
100 current_track = Track {
101 name: arguments.track_name.unwrap_or("".to_string()),
105 current_track = get_track()
106 .ok_or_else(|| Error::new(Other, "No Artist/Song could be found :("))?
109 print_lyrics(current_track, arguments.show_title).await