We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d4484e6 commit b6732a1Copy full SHA for b6732a1
src/modules/args.rs
@@ -1,3 +1,4 @@
1
+use anyhow::{anyhow, Result};
2
use clap::{Parser, ValueEnum};
3
use serde::{Deserialize, Serialize};
4
use strum_macros::AsRefStr;
@@ -17,7 +18,7 @@ pub struct Cli {
17
18
pub units: Vec<UnitArg>,
19
20
/// Output language [e.g.: en_US]
- #[arg(short, long, global = true)]
21
+ #[arg(short, long, value_parser = has_min_length)]
22
pub language: Option<String>,
23
24
/// Save the supplied values as default
@@ -79,3 +80,10 @@ pub enum UnitArg {
79
80
#[value(name = "(in)ch", alias = "in")]
81
Inch,
82
}
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