#[macro_use]
extern crate cursive;
#[macro_use]
extern crate serde;
use std::{path::PathBuf, process::exit};
use application::{Application, setup_logging};
use config::set_configuration_base_path;
use log::error;
use ncspot::program_arguments;
mod application;
mod authentication;
mod cli;
mod command;
mod commands;
mod config;
mod events;
mod ext_traits;
mod library;
mod model;
mod panic;
mod queue;
mod serialization;
mod sharing;
mod spotify;
mod spotify_api;
mod spotify_url;
mod spotify_worker;
mod theme;
mod traits;
mod ui;
mod utils;
#[cfg(unix)]
mod ipc;
#[cfg(feature = "mpris")]
mod mpris;
fn main() -> Result<(), String> {
panic::register_backtrace_panic_handler();
let matches = program_arguments().get_matches();
if let Some(filename) = matches.get_one::<PathBuf>("debug") {
setup_logging(filename).expect("logger could not be initialized");
}
set_configuration_base_path(matches.get_one::<PathBuf>("basepath").cloned());
match matches.subcommand() {
Some(("info", _subcommand_matches)) => cli::info(),
Some((_, _)) => unreachable!(),
None => {
let mut application =
match Application::new(matches.get_one::<String>("config").cloned()) {
Ok(application) => application,
Err(error) => {
eprintln!("{error}");
error!("{error}");
exit(-1);
}
};
application.run()
}
}?;
Ok(())
}