Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(cli): added command to expose metadata of individual words

Elijah Potter47d5b195d2fb
diff --git a/harper-cli/src/main.rs b/harper-cli/src/main.rs
index ef57427b6..843457c7b 100644
--- a/harper-cli/src/main.rs
+++ b/harper-cli/src/main.rs
@@ -31,7 +31,9 @@ enum Args {
/// The file you wish to display the spans.
file: PathBuf,
},
- /// Emit decompressed, line-separated list of words in Harper's dictionary.
+ /// Get the metadata associated with a particular word.
+ Metadata { word: String },
+ /// Emit a decompressed, line-separated list of the words in Harper's dictionary.
Words,
}
@@ -134,6 +136,15 @@ fn main() -> anyhow::Result<()> {
println!("{}", word_str);
}
+ Ok(())
+ }
+ Args::Metadata { word } => {
+ let dict = FstDictionary::curated();
+ let metadata = dict.get_word_metadata_str(&word);
+ let json = serde_json::to_string_pretty(&metadata).unwrap();
+
+ println!("{json}");
+
Ok(())
}
}
diff --git a/justfile b/justfile
index 7a0662df3..c2afc4b25 100644
--- a/justfile
+++ b/justfile
@@ -239,6 +239,10 @@ userdictoverlap:
just searchdictfor $line 2> /dev/null
done < $USER_DICT_FILE
+# Get the metadata associated with a particular word in Harper's dictionary as JSON.
+getmetadata word:
+ cargo run --bin harper-cli -- metadata {{word}}
+
bump-versions:
#! /bin/bash
set -eo pipefail