mod cli;
mod index;
mod select;
mod song;
use std::{
io::{Error, ErrorKind},
path::PathBuf,
};
fn main() -> std::io::Result<()> {
let command = cli::command();
let matches = command.get_matches();
let path = match matches.get_one("path") {
Some(path) => path,
None => &PathBuf::from("."),
};
let subcommand = matches.subcommand();
match subcommand {
Some(("index", _)) => {
index::populate(&path)?;
}
Some(("complete", args)) => {
cli::complete(args.get_one("shell").unwrap_or(&String::from("bash")));
}
Some((str, args)) => {
let songs = index::get(&path).map_err(|_| {
Error::new(
ErrorKind::NotFound,
"Generate an index file before querying!",
)
})?;
if let Some(play_paths) = select::filter(&songs, str) {
let separator = match args.get_one("null") {
Some(&true) => "\0",
_ => "\n",
};
print!("{}", play_paths.join(separator));
}
}
None => {}
}
Ok(())
}