#![warn(clippy::pedantic)]
#![warn(clippy::nursery)]
#![forbid(unsafe_code)]
mod config;
mod invidious;
mod player;
mod song;
mod songtag;
#[cfg(feature = "mpris")]
mod souvlaki;
mod ui;
use config::Termusic;
use std::path::Path;
extern crate tuirealm;
use ui::{UI, VERSION};
fn main() {
let mut config = Termusic::default();
config.load().unwrap_or_default();
let mut args: Vec<String> = std::env::args().collect();
args.remove(0);
let mut should_exit = false;
for i in args {
let i = i.as_str();
match i {
"-v" | "--version" => {
println!("Termusic version is: {}", VERSION);
should_exit = true;
}
"-h" | "--help" => {
println!(
r"Termusic help:
Usage: termusic [DIRECTORY] [OPTIONS]
-v or --version print version and exit.
-h or --help print this message and exit.
directory: start termusic with directory.
no arguments: start termusic with ~/.config/termusic/config.toml"
);
should_exit = true;
}
_ => {
let p = Path::new(i);
let mut p_string = String::new();
if p.exists() {
if p.has_root() {
if let Ok(p1) = p.canonicalize() {
p_string = p1.as_path().to_string_lossy().to_string();
}
} else if let Ok(p_base) = std::env::current_dir() {
let p2 = p_base.join(&p);
if let Ok(p3) = p2.canonicalize() {
p_string = p3.as_path().to_string_lossy().to_string();
}
}
config.music_dir_from_cli = Some(p_string);
} else {
println!(
r"Unknown arguments
Termusic help:
Usage: termusic [DIRECTORY] [OPTIONS]
-v or --version print version and exit.
-h or --help print this message and exit.
directory: start termusic with directory.
no arguments: start termusic with ~/.config/termusic/config.toml"
);
should_exit = true;
}
}
}
}
if should_exit {
return;
}
UI::new(&config).run();
}