From 39632ad9026e2b65389b1fd914dda5c1dc92edc6 Mon Sep 17 00:00:00 2001 From: Shinichi Kogai Date: Fri, 25 May 2018 17:34:04 +0900 Subject: [PATCH] Fix lack of newline --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 53 ++++++++++++++++++++++------------------------------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57c42e8..40ba0e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -988,7 +988,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "trs" -version = "0.5.2" +version = "0.5.3" dependencies = [ "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", "flame 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 5edb7c9..78c090e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "trs" -version = "0.5.2" +version = "0.5.3" authors = ["shinichi kogai "] categories = ["command-line-utilities"] diff --git a/src/main.rs b/src/main.rs index f8fe65d..30e8612 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,21 +41,6 @@ fn translate_between( } fn run() { - let arg_of_dictionary = Arg::with_name("dictionary") - .index(1) - .takes_value(true) - .multiple(true); - - let arg_of_to = Arg::with_name("to-target-language") - .index(1) - .takes_value(true) - .multiple(true); - - let arg_of_from = Arg::with_name("from-target-language") - .index(1) - .takes_value(true) - .multiple(true); - let matches = App::new(crate_name!()) .version(crate_version!()) .about("CLI tool for English learners") @@ -75,22 +60,28 @@ fn run() { .subcommands(vec![ SubCommand::with_name("dictionary") .about("See formal English definition of the words") - .arg(&arg_of_dictionary), - SubCommand::with_name("d") - .about("Alias for dictionary") - .arg(arg_of_dictionary), + .arg( + Arg::with_name("dictionary") + .index(1) + .takes_value(true) + .multiple(true), + ), SubCommand::with_name("from") .about("Set the words that translate from target language to english") - .arg(&arg_of_from), - SubCommand::with_name("f") - .about("Alias for from") - .arg(arg_of_from), + .arg( + Arg::with_name("from-target-language") + .index(1) + .takes_value(true) + .multiple(true), + ), SubCommand::with_name("to") .about("Set the words that translate to") - .arg(&arg_of_to), - SubCommand::with_name("t") - .about("Alias for to") - .arg(arg_of_to), + .arg( + Arg::with_name("to-target-language") + .index(1) + .takes_value(true) + .multiple(true), + ), ]) .get_matches(); @@ -116,7 +107,7 @@ fn run() { }; let result = match matches.subcommand() { - ("dictionary", Some(cmd)) | ("d", Some(cmd)) => { + ("dictionary", Some(cmd)) => { let namespace = cache::Namespace::Dictionary; let query_words = values_t!(cmd.values_of("dictionary"), String).unwrap_or(vec![]); println!("{:#?}", query_words); @@ -131,7 +122,7 @@ fn run() { }; definitions } - ("to", Some(cmd)) | ("t", Some(cmd)) => { + ("to", Some(cmd)) => { let query_words = values_t!(cmd.values_of("to-target-language"), String).unwrap_or(vec![]); let target_language = default_language; @@ -142,7 +133,7 @@ fn run() { &mut fs_cache, ) } - ("from", Some(cmd)) | ("f", Some(cmd)) => { + ("from", Some(cmd)) => { let query_words = values_t!(cmd.values_of("from-target-language"), String).unwrap_or(vec![]); let target_language = "en".to_owned(); @@ -156,7 +147,7 @@ fn run() { _ => unreachable!(), }; - let _ = io::stdout().write(result.as_bytes()); + let _ = io::stdout().write(format!("{}\n", result).as_bytes()); let _ = span_of("garbage_collect", || fs_cache.garbage_colloect()); }