aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2025-10-27 09:31:48 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-01-13 15:21:31 +0100
commita6a46c403c780144e55a337a88af49fa9aa55acd (patch)
tree51ed900230babc6172341316fdaaaf73c0e98270
parent6b098702c6f7df5d400b76031618506dbdda02a5 (diff)
downloadmihi-a6a46c403c780144e55a337a88af49fa9aa55acd.tar.gz
mihi-a6a46c403c780144e55a337a88af49fa9aa55acd.zip
Add basic validation for verbs and pronouns
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
-rw-r--r--crates/cli/src/inflection.rs4
-rw-r--r--crates/cli/src/run.rs2
-rw-r--r--crates/cli/src/words.rs32
-rw-r--r--lib/mihi/src/lib.rs16
4 files changed, 40 insertions, 14 deletions
diff --git a/crates/cli/src/inflection.rs b/crates/cli/src/inflection.rs
index 1b9d932..7d2f195 100644
--- a/crates/cli/src/inflection.rs
+++ b/crates/cli/src/inflection.rs
@@ -125,8 +125,8 @@ pub fn print_full_inflection_for(word: Word) -> Result<(), String> {
match word.category {
Category::Noun => print_noun_inflection(&word)?,
Category::Adjective => print_adjective_inflection(&word)?,
- Category::Verb => todo!(),
- Category::Pronoun => todo!(),
+ Category::Verb => {} // TODO
+ Category::Pronoun => {} // TODO
Category::Adverb
| Category::Preposition
| Category::Conjunction
diff --git a/crates/cli/src/run.rs b/crates/cli/src/run.rs
index 3e1b866..10e0721 100644
--- a/crates/cli/src/run.rs
+++ b/crates/cli/src/run.rs
@@ -23,7 +23,7 @@ fn help(msg: Option<&str>) {
println!("Options:");
println!(" -c, --category <CATEGORY>\tOnly ask for words on the given <CATEGORY>.");
println!(" -e, --exercises\t\tOnly practice with exercises.");
- println!(" -f, --flag\t\tFilter words by a boolean flag. Multiple flags can be provided.");
+ println!(" -f, --flag\t\t\tFilter words by a boolean flag. Multiple flags can be provided.");
println!(" -h, --help\t\t\tPrint this message.");
println!(" -k, --kind <KIND>\t\tOnly ask for exercises for the given <KIND>.");
}
diff --git a/crates/cli/src/words.rs b/crates/cli/src/words.rs
index ba86041..23a3946 100644
--- a/crates/cli/src/words.rs
+++ b/crates/cli/src/words.rs
@@ -248,7 +248,7 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result<Word, String>
};
let inflection_id = match category {
- Category::Noun | Category::Adjective => {
+ Category::Noun | Category::Adjective | Category::Verb => {
let Ok(inflection) = Text::new("Inflection:")
.with_initial_value(word.inflection_id().unwrap_or(0).to_string().as_str())
.prompt()
@@ -262,7 +262,6 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result<Word, String>
}
_ => None,
};
- let kind = kind.trim().to_string();
// TODO: refine guess once the inflection is known: select from possible values.
let kind = match category {
@@ -276,14 +275,28 @@ fn ask_for_word_based_on(enunciated: String, word: Word) -> Result<Word, String>
_ => String::from("-"),
};
- let Ok(regular) = Confirm::new("Regular:").with_default(word.regular).prompt() else {
- return Err("abort!".to_string());
+ let regular = if matches!(
+ category,
+ Category::Noun | Category::Adjective | Category::Verb
+ ) {
+ let Ok(regular) = Confirm::new("Regular:").with_default(word.regular).prompt() else {
+ return Err("abort!".to_string());
+ };
+ regular
+ } else {
+ true
};
- let Ok(locative) = Confirm::new("Locative:")
- .with_default(word.locative)
- .prompt()
- else {
- return Err("abort!".to_string());
+
+ let locative = if matches!(category, Category::Noun) {
+ let Ok(locative) = Confirm::new("Locative:")
+ .with_default(word.locative)
+ .prompt()
+ else {
+ return Err("abort!".to_string());
+ };
+ locative
+ } else {
+ false
};
let Ok(raw_weight) = Text::new("Weight:")
@@ -597,6 +610,7 @@ fn show_info(word: Word) -> Result<(), String> {
}
// Conjugation, declension + kind.
+ // TODO: to_human
match word.conjugation_id {
Some(id) => println!("Conjugation: {}", id),
None => match word.declension_id {
diff --git a/lib/mihi/src/lib.rs b/lib/mihi/src/lib.rs
index 36da6d2..78400f2 100644
--- a/lib/mihi/src/lib.rs
+++ b/lib/mihi/src/lib.rs
@@ -375,6 +375,19 @@ pub fn create_word(word: Word) -> Result<(), String> {
))
}
},
+ Category::Verb => match word.conjugation_id {
+ Some(1..6) => {
+ if word.kind.as_str() != "verb" {
+ return Err(format!("bad kind for verb"));
+ }
+ }
+ Some(val) => return Err(format!("the conjugation ID '{val}' is not valid")),
+ None => {
+ return Err(String::from(
+ "you have to provide the conjugation ID for this verb",
+ ))
+ }
+ },
Category::Adverb
| Category::Preposition
| Category::Conjunction
@@ -384,8 +397,7 @@ pub fn create_word(word: Word) -> Result<(), String> {
return Err(format!("no inflection allowed for '{}'", word.category));
}
}
- // TODO
- _ => {
+ Category::Unknown | Category::Pronoun => {
return Err(format!(
"you cannot create a word from the '{}' category",
word.category