feat(cli): allow filtering of parts of speech
This commit is contained in:
+19
@@ -2,12 +2,28 @@ use clap::Parser;
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
static POSSIBLE_PARTS_OF_SPEECH: &[&str] = &[
|
||||||
|
"noun",
|
||||||
|
"verb",
|
||||||
|
"adjective",
|
||||||
|
"adverb",
|
||||||
|
"pronoun",
|
||||||
|
"preposition",
|
||||||
|
"conjunction",
|
||||||
|
"interjection",
|
||||||
|
"exclamation",
|
||||||
|
"determiner",
|
||||||
|
"article",
|
||||||
|
];
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
word: String,
|
word: String,
|
||||||
#[arg(short, long, default_value = "en")]
|
#[arg(short, long, default_value = "en")]
|
||||||
language: String,
|
language: String,
|
||||||
|
#[arg(short, long, default_values = POSSIBLE_PARTS_OF_SPEECH)]
|
||||||
|
parts_of_speech: Vec<String>,
|
||||||
#[arg(short, long, action = clap::ArgAction::SetTrue)]
|
#[arg(short, long, action = clap::ArgAction::SetTrue)]
|
||||||
examples: bool,
|
examples: bool,
|
||||||
}
|
}
|
||||||
@@ -52,6 +68,9 @@ async fn main() {
|
|||||||
let result = result.unwrap();
|
let result = result.unwrap();
|
||||||
|
|
||||||
for entry in result.entries {
|
for entry in result.entries {
|
||||||
|
if !args.parts_of_speech.contains(&entry.part_of_speech) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
println!(
|
println!(
|
||||||
"{} ({})",
|
"{} ({})",
|
||||||
result.word.yellow().underline(),
|
result.word.yellow().underline(),
|
||||||
|
|||||||
Reference in New Issue
Block a user