Skip to content

Commit

Permalink
- update code to support TA - Tamil language
Browse files Browse the repository at this point in the history
- add README to show how to add new language
- add option to download wordlist from different repository
- add assertions for incorrectly downloaded files etc.

- update README
  • Loading branch information
arcturusannamalai committed Dec 19, 2023
1 parent 614d76c commit 549d6a0
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 150 deletions.
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
Adding New Language
===================
Update the language code in the list at


Update the language wordlist
============================
```
$ cargo run -- --lang ta --update-langs --wordlist-url https://raw.githubusercontent.com/arcturusannamalai/wordlists/main/
Finished dev [unoptimized + debuginfo] target(s) in 0.17s
Running `target/debug/dym --lang ta --update-langs --wordlist-url 'https://raw.githubusercontent.com/arcturusannamalai/wordlists/main/'`
Downloading English word list...
Accessing URL: https://raw.githubusercontent.com/arcturusannamalai/wordlists/main//en
[00:00:00] [############################################################################################################################] 4.12MiB/4.12MiB (0s)
Downloading Tamil word list...
Accessing URL: https://raw.githubusercontent.com/arcturusannamalai/wordlists/main//ta
[00:00:00] [############################################################################################################################] 1.73MiB/1.73MiB (0s)
```

Run did you mean:
================
e.g.
```
cargo run -- --lang ta கலஅ
Compiling didyoumean v1.1.4 (/Users/user/devel/rust-in-action/didyoumean)
Finished dev [unoptimized + debuginfo] target(s) in 1.18s
Running `target/debug/dym --lang ta 'கலஅ'`
Did you mean?
1. கலி
2. கலை
3. கல்
4. அ
5. அகல்
```


For more info see the help text and options,
```
$ cargo run -- --help
didyoumean user$ cargo run -- --help
Compiling didyoumean v1.1.4 (/Users/user/devel/rust-in-action/didyoumean)
Finished dev [unoptimized + debuginfo] target(s) in 2.24s
Running `target/debug/dym --help`
didyoumean 1.1.4
Hisbaan Noorani
Did You Mean: A cli spelling corrector
USAGE:
dym [OPTIONS] [SEARCH_TERM]
ARGS:
<SEARCH_TERM>
OPTIONS:
-c, --clean-output
Print a clean version of the output without the title, numbers or colour.
-h, --help
Print help information
-l, --lang <LANG>
Select the desired language using its locale code. For example, English would have the
locale code en and French would have the locale code fr. See --print-langs for a list of
locale codes and the corresponding languages.
[default: en]
-n, --number <NUMBER>
Change the number of words the program will print. The default value is five.
[default: 5]
--print-langs
Display a list of supported languages and their respective locale codes.
--update-langs
Update all language files from the repository specified by CLI @wordlist-url@.
-v, --verbose
Print verbose output including the edit distance of the found word to the queried word.
-V, --version
Print version information
-w, --wordlist-url <WORDLIST_URL>
Wordlist repository URL. The default value is
'https://raw.githubusercontent.com/hisbaan/wordlists/main'
[default: https://raw.githubusercontent.com/hisbaan/wordlists/main]
-y, --yank
Yank (copy) the selected word to the system clipboard. If no word is selected, the
clipboard will not be altered.
```



108 changes: 58 additions & 50 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,62 @@ use clap::Parser;
#[derive(Parser)]
#[clap(author = "Hisbaan Noorani", version = "1.1.4", about = "Did You Mean: A cli spelling corrector", long_about = None)]
pub struct Cli {
pub search_term: Option<String>,
#[clap(
short = 'n',
long = "number",
default_value_t = 5,
help = "Change the number of matches printed",
long_help = "Change the number of words the program will print. The default value is five."
)]
pub number: usize,
#[clap(
short = 'c',
long = "clean-output",
help = "Print clean output",
long_help = "Print a clean version of the output without the title, numbers or colour."
)]
pub clean_output: bool,
#[clap(
short = 'v',
long = "verbose",
help = "Print verbose output",
long_help = "Print verbose output including the edit distance of the found word to the queried word."
)]
pub verbose: bool,
#[clap(
short = 'y',
long = "yank",
help = "Yank (copy) to the system cliboard",
long_help = "Yank (copy) the selected word to the system clipboard. If no word is selected, the clipboard will not be altered."
)]
pub yank: bool,
#[clap(
short = 'l',
long = "lang",
help = "Select the desired language using the locale code (en, fr, sp, etc.)",
long_help = "Select the desired language using its locale code. For example, English would have the locale code en and French would have the locale code fr. See --print-langs for a list of locale codes and the corresponding languages.",
default_value = "en"
)]
pub lang: String,
#[clap(
long = "print-langs",
help = "Display a list of supported languages",
long_help = "Display a list of supported languages and their respective locale codes."
)]
pub print_langs: bool,
#[clap(
long = "update-langs",
help = "Update all language files",
long_help = "Update all language files from the repository https://github.com/hisbaan/wordlists."
)]
pub update_langs: bool,
pub search_term: Option<String>,
#[clap(
short = 'n',
long = "number",
default_value_t = 5,
help = "Change the number of matches printed",
long_help = "Change the number of words the program will print. The default value is five."
)]
pub number: usize,
#[clap(
short = 'c',
long = "clean-output",
help = "Print clean output",
long_help = "Print a clean version of the output without the title, numbers or colour."
)]
pub clean_output: bool,
#[clap(
short = 'v',
long = "verbose",
help = "Print verbose output",
long_help = "Print verbose output including the edit distance of the found word to the queried word."
)]
pub verbose: bool,
#[clap(
short = 'y',
long = "yank",
help = "Yank (copy) to the system cliboard",
long_help = "Yank (copy) the selected word to the system clipboard. If no word is selected, the clipboard will not be altered."
)]
pub yank: bool,
#[clap(
short = 'l',
long = "lang",
help = "Select the desired language using the locale code (en, fr, sp, etc.)",
long_help = "Select the desired language using its locale code. For example, English would have the locale code en and French would have the locale code fr. See --print-langs for a list of locale codes and the corresponding languages.",
default_value = "en"
)]
pub lang: String,
#[clap(
long = "print-langs",
help = "Display a list of supported languages",
long_help = "Display a list of supported languages and their respective locale codes."
)]
pub print_langs: bool,
#[clap(
long = "update-langs",
help = "Update all language files",
long_help = "Update all language files from the repository specified by CLI @wordlist-url@."
)]
pub update_langs: bool,
#[clap(
short = 'w',
long = "wordlist-url",
help = "Wordlist repository URL",
long_help = "Wordlist repository URL. The default value is 'https://raw.githubusercontent.com/hisbaan/wordlists/main'",
default_value = "https://raw.githubusercontent.com/hisbaan/wordlists/main"
)]
pub wordlist_url: String,
}
2 changes: 2 additions & 0 deletions src/langs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub static LOCALES: phf::Map<&'static str, &'static str> = phf_map! {
"st" => "Sesotho",
"sv" => "Swedish",
"sw" => "Swahili",
"ta" => "Tamil",
"tg" => "Tajik",
"th" => "Thai",
"tk" => "Turkmen",
Expand Down Expand Up @@ -129,6 +130,7 @@ pub static SUPPORTED_LANGS: phf::Map<&'static str, &'static str> = phf_map! {
"st" => "Sesotho",
"sv" => "Swedish",
"sw" => "Swahili",
"ta" => "Tamil",
"tg" => "Tajik",
"tk" => "Turkmen",
"tl" => "Tagalog",
Expand Down
Loading

0 comments on commit 549d6a0

Please sign in to comment.