0.3.2. get_audio subcommand.
This commit is contained in:
parent
ef50c64d87
commit
4b70b0708d
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -47,7 +47,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "monokakido"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
dependencies = [
|
||||
"miniserde",
|
||||
"miniz_oxide",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "monokakido"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
edition = "2021"
|
||||
description = "A Rust library for parsing and interpreting the Monokakido dictionary format."
|
||||
license = "MIT"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::io::Write;
|
||||
|
||||
use monokakido::{Error, MonokakidoDict};
|
||||
|
||||
fn print_help() {
|
||||
|
@ -46,6 +48,16 @@ fn list_audio(dict_name: &str, keyword: &str) -> Result<(), Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn get_audio(dict_name: &str, id: &str) -> Result<(), Error> {
|
||||
let id = id.strip_suffix(".aac").unwrap_or(id);
|
||||
let mut dict = MonokakidoDict::open(dict_name)?;
|
||||
let aac = dict.audio.as_mut().ok_or(Error::MissingAudio)?.get(id)?;
|
||||
let mut stdout = std::io::stdout().lock();
|
||||
// TODO: for ergonomics/failsafe, check if stdout is a TTY
|
||||
stdout.write_all(aac)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn list_dicts() -> Result<(), Error> {
|
||||
for dict in MonokakidoDict::list()? {
|
||||
println!("{}", dict?);
|
||||
|
@ -63,6 +75,13 @@ fn main() {
|
|||
Err(Error::InvalidArg)
|
||||
}
|
||||
}
|
||||
Some("get_audio") => {
|
||||
if let (Some(dict_name), Some(id)) = (args.next(), args.next()) {
|
||||
get_audio(&dict_name, &id)
|
||||
} else {
|
||||
Err(Error::InvalidArg)
|
||||
}
|
||||
}
|
||||
Some("list_items") => {
|
||||
if let (Some(dict_name), Some(keyword)) = (args.next(), args.next()) {
|
||||
list_items(&dict_name, &keyword)
|
||||
|
@ -82,7 +101,7 @@ fn main() {
|
|||
print_help();
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(Error::InvalidArg),
|
||||
_ => Err(Error::InvalidSubcommand),
|
||||
};
|
||||
|
||||
if let Err(e) = res {
|
||||
|
|
|
@ -25,6 +25,8 @@ pub enum Error {
|
|||
FmtError,
|
||||
IndexDoesntExist,
|
||||
XmlError,
|
||||
MissingAudio,
|
||||
InvalidSubcommand,
|
||||
}
|
||||
|
||||
impl From<IoError> for Error {
|
||||
|
|
Loading…
Reference in a new issue