aboutsummaryrefslogtreecommitdiff
path: root/crates/cli/src/run.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-01-13 15:27:05 +0100
committerMiquel Sabaté Solà <mssola@mssola.com>2026-01-13 15:27:05 +0100
commit43632164dcacb3424ccb9ceba76ddfd7586cb59c (patch)
tree5c8d42f793326fecef757a7e60eb94ad45c13511 /crates/cli/src/run.rs
parentbb3bbcfd018816a80077a6c1f96f842d2bf5f3a4 (diff)
parent472d7fb9d37ec838fc69692cf24c8cb4a68af47a (diff)
downloadmihi-43632164dcacb3424ccb9ceba76ddfd7586cb59c.tar.gz
mihi-43632164dcacb3424ccb9ceba76ddfd7586cb59c.zip
Merge branch 'inflection'
Diffstat (limited to 'crates/cli/src/run.rs')
-rw-r--r--crates/cli/src/run.rs39
1 files changed, 4 insertions, 35 deletions
diff --git a/crates/cli/src/run.rs b/crates/cli/src/run.rs
index 0046d47..10e0721 100644
--- a/crates/cli/src/run.rs
+++ b/crates/cli/src/run.rs
@@ -6,6 +6,8 @@ use std::io::Write;
use std::process::Command;
use tempfile::NamedTempFile;
+use crate::locale::{current_locale, Locale};
+
// Maximum number of times a word has to be run in order to increase the number
// of successful runs.
const MAX_STEPS: usize = 5;
@@ -21,39 +23,11 @@ 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>.");
}
-// Locale represents the locales accepted for delivering answers on this
-// tool. That is, it's not about i18n on the strings for this application. but
-// rather the different translations accepted in places like
-// `Word.translations`.
-enum Locale {
- English,
- Catalan,
-}
-
-impl Locale {
- // Returns the string representation for the locale's code.
- fn to_code(&self) -> &str {
- match self {
- Self::English => "en",
- Self::Catalan => "ca",
- }
- }
-}
-
-impl std::fmt::Display for Locale {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- match self {
- Self::English => write!(f, "english"),
- Self::Catalan => write!(f, "català"),
- }
- }
-}
-
// Run the quiz for all the given `words` while expecting answers to be
// delivered in the given `locale`.
fn run_words(words: Vec<Word>, locale: &Locale) -> i32 {
@@ -323,12 +297,7 @@ pub fn run(args: Vec<String>) {
}
}
- let raw_locale = std::env::var("LC_ALL").unwrap_or("en".to_string());
- let locale = if raw_locale.starts_with("ca") {
- Locale::Catalan
- } else {
- Locale::English
- };
+ let locale = current_locale();
let words = match category {
Some(cat) => select_relevant_words(cat, &flags, 15),