Skip to content

Commit b6732a1

Browse files
authored
🐛 check language arg for min length (#68)
1 parent d4484e6 commit b6732a1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/modules/args.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::{anyhow, Result};
12
use clap::{Parser, ValueEnum};
23
use serde::{Deserialize, Serialize};
34
use strum_macros::AsRefStr;
@@ -17,7 +18,7 @@ pub struct Cli {
1718
pub units: Vec<UnitArg>,
1819

1920
/// Output language [e.g.: en_US]
20-
#[arg(short, long, global = true)]
21+
#[arg(short, long, value_parser = has_min_length)]
2122
pub language: Option<String>,
2223

2324
/// Save the supplied values as default
@@ -79,3 +80,10 @@ pub enum UnitArg {
7980
#[value(name = "(in)ch", alias = "in")]
8081
Inch,
8182
}
83+
84+
fn has_min_length(s: &str) -> Result<String> {
85+
match s.len() < 2 {
86+
true => Err(anyhow!("\n The language code must be at least two characters long.")),
87+
_ => Ok(s.to_string()),
88+
}
89+
}

0 commit comments

Comments
 (0)