aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-03-13 22:43:47 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2024-03-13 22:43:47 +0100
commit738ec06d26a2a19bdda8a992d2250e731d954631 (patch)
treec963a76fc51d5d4712026efaf9e5ac6accba9526 /src/main.rs
parent4adf8d5182b7ad3720e3160e0f4530547625dbce (diff)
Add rust implementation test
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..13b7e37
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,78 @@
+// mod configuration;
+mod lyrics_engine;
+mod sources;
+
+use std::io::{Result, Error, ErrorKind::Other};
+use clap::{Parser};
+
+use sources::{enable, disable, get_track, reset, list};
+use lyrics_engine::print_lyrics;
+
+#[derive(Parser, Debug)]
+#[command(version, about, long_about = None)]
+struct Arguments {
+
+ // Positional Arguments
+ /// Specify the artist.
+ artist: Option<String>,
+
+ /// Specify the artist.
+ track_name: Option<String>,
+
+ /// Show title of track if present
+ #[arg(short = 't', long)]
+ show_title: bool,
+
+ /// Lists all sources
+ #[arg(short, long)]
+ list_sources: bool,
+
+ /// Enables a source
+ #[arg(short, long, value_name = "SOURCE")]
+ enable_source: Option<String>,
+
+ #[arg(short, long, value_name = "SOURCE")]
+ disable_source: Option<String>,
+
+ #[arg(short, long, value_name = "SOURCE")]
+ reset_source: Option<String>,
+}
+
+pub struct Track {
+ pub name: String,
+ pub artist: String
+}
+
+#[tokio::main]
+async fn main() -> Result<()> {
+ let arguments = Arguments::parse();
+
+ if arguments.list_sources {
+ return list();
+ }
+
+ if let Some(source_name) = arguments.enable_source {
+ return enable(source_name);
+ }
+
+ if let Some(source_name) = arguments.disable_source {
+ return disable(source_name);
+ }
+
+ if let Some(source_name) = arguments.reset_source {
+ return reset(source_name);
+ }
+
+ let current_track: Track;
+ if let Some(artist) = arguments.artist {
+ current_track = Track {
+ name: arguments.track_name.unwrap_or("".to_string()),
+ artist: artist
+ };
+ } else {
+ current_track = get_track()
+ .ok_or_else(|| Error::new(Other, "No Artist/Song could be found :("))?
+ }
+
+ print_lyrics(current_track, arguments.show_title).await
+}