Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions harper-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ enum Args {
/// Overlapping lints are removed by default. This option disables that behavior.
#[arg(short = 'o', long)]
keep_overlapping_lints: bool,
/// Specify the dialect.
#[arg(short, long, default_value = Dialect::American.to_string())]
dialect: Dialect,
/// Specify the dialect. Common synonyms, abbreviations, and codes are supported.
#[arg(short, long, default_value = "us")]
dialect: String,
/// Path to the user dictionary.
#[arg(short, long, default_value = config_dir().unwrap().join("harper-ls/dictionary.txt").into_os_string())]
user_dict_path: PathBuf,
Expand Down Expand Up @@ -211,11 +211,13 @@ fn main() -> anyhow::Result<()> {
ignore,
only,
keep_overlapping_lints,
dialect,
dialect: dialect_str,
user_dict_path,
// TODO workspace_dict_path?
file_dict_path,
} => {
let dialect = parse_dialect(&dialect_str)
.map_err(|e| anyhow!("Invalid dialect '{}': {}", dialect_str, e))?;

lint(
markdown_options,
curated_dictionary,
Expand Down Expand Up @@ -945,6 +947,19 @@ fn main() -> anyhow::Result<()> {
}
}

/// Parse a dialect string into a Dialect enum value.
/// Supports common synonyms, abbreviations, and codes.
fn parse_dialect(dialect: &str) -> anyhow::Result<Dialect> {
match dialect.to_lowercase().as_str() {
"us" | "usa" | "america" | "american" | "en-us" | "en_us" => Ok(Dialect::American),
"uk" | "gb" | "british" | "britain" | "en-gb" | "en_gb" => Ok(Dialect::British),
"au" | "aus" | "australia" | "australian" | "en-au" | "en_au" => Ok(Dialect::Australian),
"in" | "india" | "indian" | "bharat" | "en-in" | "en_in" => Ok(Dialect::Indian),
"ca" | "canada" | "canadian" | "en-ca" | "en_ca" => Ok(Dialect::Canadian),
_ => Err(anyhow!("Unknown dialect: {}", dialect)),
}
}

/// Split a dictionary line into its word and annotation segments
fn line_to_parts(line: &str) -> (String, String) {
if let Some((word, annot)) = line.split_once('/') {
Expand Down