tagdex 1.0.0

An mp3 tag indexer written in Rust.
Documentation
mod cli;
mod index;
mod select;
mod song;

use std::{
  io::{Error, ErrorKind},
  path::PathBuf,
};

fn main() -> std::io::Result<()> {
  // Get command specification.
  let command = cli::command();

  // Get path argument and subcommand name.
  let matches = command.get_matches();
  let path = match matches.get_one("path") {
    Some(path) => path,
    None => &PathBuf::from("."),
  };
  let subcommand = matches.subcommand();

  match subcommand {
    // Handle index generation.
    Some(("index", _)) => {
      index::populate(&path)?;
    }
    // Handle completion file generation.
    Some(("complete", args)) => {
      cli::complete(args.get_one("shell").unwrap_or(&String::from("bash")));
    }
    // Handle song selection.
    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) {
        // Use the separator specified by the "--null" flag.
        let separator = match args.get_one("null") {
          Some(&true) => "\0",
          _ => "\n",
        };
        print!("{}", play_paths.join(separator));
      }
    }
    None => {}
  }

  Ok(())
}