Skip to content

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

feat: `just getmetadata` and `harper-cli metadata` now accept multiple words (#1847)

Andrew Dunbar6d70948397bc
diff --git a/harper-cli/src/main.rs b/harper-cli/src/main.rs
index bdb6b731d..aa2103d19 100644
--- a/harper-cli/src/main.rs
+++ b/harper-cli/src/main.rs
@@ -88,8 +88,8 @@ enum Args {
#[arg(short, long, value_enum, default_value_t = AnnotationType::Upos)]
annotation_type: AnnotationType,
},
- /// Get the metadata associated with a particular word.
- Metadata { word: String },
+ /// Get the metadata associated with one or more words.
+ Metadata { words: Vec<String> },
/// Get all the forms of a word using the affixes.
Forms { line: String },
/// Emit a decompressed, line-separated list of the words in Harper's dictionary.
@@ -361,12 +361,14 @@ fn main() -> anyhow::Result<()> {
Ok(())
}
- Args::Metadata { word } => {
- let metadata = dictionary.get_word_metadata_str(&word);
- let json = serde_json::to_string_pretty(&metadata).unwrap();
-
+ Args::Metadata { words } => {
+ let mut results = BTreeMap::new();
+ for word in words {
+ let metadata = dictionary.get_word_metadata_str(&word);
+ results.insert(word, metadata);
+ }
+ let json = serde_json::to_string_pretty(&results).unwrap();
println!("{json}");
-
Ok(())
}
Args::SummarizeLintRecord { file } => {
diff --git a/justfile b/justfile
index b4bece3d4..d7c6ff7c2 100644
--- a/justfile
+++ b/justfile
@@ -352,9 +352,9 @@ 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}}
+# Get the metadata associated with one or more words in Harper's dictionary as JSON.
+getmetadata *words:
+ cargo run --bin harper-cli -- metadata {{words}}
# Get all the forms of a word using the affixes.
getforms word:
cargo run --bin harper-cli -- forms {{word}}