blob: 6a556e8925cabd439e872b53a9b4933995e35cd6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#![allow(non_upper_case_globals)]
#![allow(unused_variables)]
#![feature(let_chains)]
pub mod correct;
pub mod display;
pub mod lookup;
pub mod state;
// https://github.com/rust-lang/rfcs/issues/1349
const version: &str = env!("CARGO_PKG_VERSION");
const index_path: &str = env!("index_path");
const dictionary_path: &str = env!("dictionary_path");
const wiktionary_api_path: &str = "https://en.wiktionary.org/w/api.php?action=parse&format=json&formatversion=2&prop=wikitext&page=";
pub fn handle_word(word: String, state: &state::State) {
// if lets are kinda clunky
if let Some(definition) = lookup::lookup(&word).unwrap() {
display::display(definition, &state);
} else if let Some(corrected) = correct::correct(&word) {
println!("Could not find word {}, continuing with {}...", word, corrected);
if let Some(definition) = lookup::lookup(&corrected).unwrap() {
display::display(definition, &state);
} else {
println!("Could not find corrected word {}.", corrected);
}
} else {
println!("Could not find word {}. Check your spelling?", word);
}
}
// mut state: State, yet state: &mut State?? huh??
pub fn handle_parameter(word: &str, state: &mut state::State) {
match word { // todo: extend
"--help" => {
println!("dictionarium {}\n", version);
println!("Usage: dictionarium <word>");
},
_ => {
println!("Unknown flag \"{}\".", word);
}
}
}
|