diff --git a/src/cli.rs b/src/cli.rs index 6adafd9..624a82f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -99,7 +99,6 @@ impl<'a> Command<'a> { /** * Adds arguments to the command */ - pub fn with_args(mut self, args: &Vec) -> Command<'a> { if self.args.is_none() { self.args = Some(vec![]); diff --git a/src/main.rs b/src/main.rs index c52d159..20f4f8e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -181,26 +181,7 @@ fn main() { let display = command.has("display"); let to = command.get_value_of("to"); - if type_of_words != "english" - && type_of_words != "latin" - && type_of_words != "inflections" - && type_of_words != "inflection" - && type_of_words != "not_packons" - && type_of_words != "not_packon" - && type_of_words != "packon" - && type_of_words != "packons" - && type_of_words != "prefixes" - && type_of_words != "prefix" - && type_of_words != "stems" - && type_of_words != "stem" - && type_of_words != "suffixes" - && type_of_words != "suffix" - && type_of_words != "tackons" - && type_of_words != "tackon" - && type_of_words != "tickons" - && type_of_words != "tickon" - && type_of_words != "unique_latin" - { + if !WordType::is_valid_word_type(&type_of_words) { println!( "Invalid type of words. Please use `help` to see the available types of words." ); diff --git a/src/use_data/mod.rs b/src/use_data/mod.rs index cbcbcad..1b5547c 100644 --- a/src/use_data/mod.rs +++ b/src/use_data/mod.rs @@ -58,6 +58,15 @@ impl WordType { _ => Err(format!("Invalid word type: {}", s)), } } + + pub fn is_valid_word_type(s: &str) -> bool { + match s { + "english" | "latin" | "inflections" | "inflection" | "not_packons" | "not_packon" + | "packon" | "packons" | "prefixes" | "prefix" | "stems" | "stem" | "suffixes" + | "suffix" | "tackons" | "tackon" | "tickons" | "tickon" | "unique_latin" => true, + _ => false, + } + } } #[derive(Debug, Serialize)] @@ -141,4 +150,10 @@ pub fn get_list( if display { println!("{}", serde_json::to_string_pretty(&list).unwrap()); } + + if to.is_some() { + let file_path = to.unwrap(); + let file = std::fs::File::create(file_path).unwrap(); + serde_json::to_writer_pretty(file, &list).unwrap(); + } }