]> git.r.bdr.sh - rbdr/lyricli/blob - src/main.rs
13b7e37903f13ff278f2165a37718ffbdb6fe19c
[rbdr/lyricli] / src / main.rs
1 // mod configuration;
2 mod lyrics_engine;
3 mod sources;
4
5 use std::io::{Result, Error, ErrorKind::Other};
6 use clap::{Parser};
7
8 use sources::{enable, disable, get_track, reset, list};
9 use lyrics_engine::print_lyrics;
10
11 #[derive(Parser, Debug)]
12 #[command(version, about, long_about = None)]
13 struct Arguments {
14
15 // Positional Arguments
16 /// Specify the artist.
17 artist: Option<String>,
18
19 /// Specify the artist.
20 track_name: Option<String>,
21
22 /// Show title of track if present
23 #[arg(short = 't', long)]
24 show_title: bool,
25
26 /// Lists all sources
27 #[arg(short, long)]
28 list_sources: bool,
29
30 /// Enables a source
31 #[arg(short, long, value_name = "SOURCE")]
32 enable_source: Option<String>,
33
34 #[arg(short, long, value_name = "SOURCE")]
35 disable_source: Option<String>,
36
37 #[arg(short, long, value_name = "SOURCE")]
38 reset_source: Option<String>,
39 }
40
41 pub struct Track {
42 pub name: String,
43 pub artist: String
44 }
45
46 #[tokio::main]
47 async fn main() -> Result<()> {
48 let arguments = Arguments::parse();
49
50 if arguments.list_sources {
51 return list();
52 }
53
54 if let Some(source_name) = arguments.enable_source {
55 return enable(source_name);
56 }
57
58 if let Some(source_name) = arguments.disable_source {
59 return disable(source_name);
60 }
61
62 if let Some(source_name) = arguments.reset_source {
63 return reset(source_name);
64 }
65
66 let current_track: Track;
67 if let Some(artist) = arguments.artist {
68 current_track = Track {
69 name: arguments.track_name.unwrap_or("".to_string()),
70 artist: artist
71 };
72 } else {
73 current_track = get_track()
74 .ok_or_else(|| Error::new(Other, "No Artist/Song could be found :("))?
75 }
76
77 print_lyrics(current_track, arguments.show_title).await
78 }