diff options
| -rw-r--r-- | README.md | 17 | ||||
| -rw-r--r-- | images/countryfetch.png | bin | 400061 -> 1595036 bytes | |||
| -rwxr-xr-x | install.sh | 2 | ||||
| -rwxr-xr-x | run.sh | 4 | ||||
| -rw-r--r-- | src/app.ts | 28 | ||||
| -rw-r--r-- | src/countries.ts | 14 | ||||
| -rw-r--r-- | src/environment/environment.ts | 2 | ||||
| -rw-r--r-- | src/util/help.ts | 24 |
8 files changed, 59 insertions, 32 deletions
@@ -19,6 +19,7 @@ git clone https://github.com/CondensedMilk7/countryfetch.git navigate to the cloned repo folder and run install: ```bash +cd ./countryfetch ./install.sh ``` @@ -43,20 +44,20 @@ alias countryfetch="~/.local/bin/countryfetch" countryfetch <arguments> ``` -available arguments: +### Arguments: -- `find <country-name>` - Find country information by name. Country names cannot have whitespaces, use kebab-case or snake_case instead. -- `sync` - Synchronizes databes, stores it in localStorage. This is done automatically, but can be triggered manually. +- `<country_name>` - Find country information by name. Country names cannot have whitespaces, use kebab-case or snake_case instead. +- `sync` - Fetches data from API and stores it in `~/.cache/countryfetch/countries.json`. This is done automatically, but can be triggered manually. - `random` - Get random country information. -example: +### Example: ``` -$ countryfetch find germany +$ countryfetch germany # output: -Country: 🇩🇪 Germany +Country: Germany 🇩🇪 Languages: German Capital: Berlin Region: Europe @@ -65,10 +66,6 @@ Currencies: Euro [€](EUR) ``` -## Known issues - -- App will not match names that include "-", which is replaced by whitespace by program. - ## Contribution I will add new features when I have time, but you don't have to wait - add them yourself! Submit pull requests, or fork it and make it your own alltogether. diff --git a/images/countryfetch.png b/images/countryfetch.png Binary files differindex cdcac7d..46eedc1 100644 --- a/images/countryfetch.png +++ b/images/countryfetch.png @@ -1,3 +1,3 @@ #!/bin/sh -deno install --allow-all ./main.ts
\ No newline at end of file +deno install --allow-all "$@" ./main.ts
\ No newline at end of file @@ -0,0 +1,4 @@ +#!/bin/sh + +# Just a short-hand to run instead of typing it out in termina during development +deno run --allow-all ./main.ts "$@"
\ No newline at end of file @@ -1,22 +1,24 @@ import { Countries } from "./countries.ts"; import { Cache } from "./util/cache.ts"; +import { help } from "./util/help.ts"; export async function app() { + const command = Deno.args[0]; const countries = new Countries(new Cache()); await countries.sync(); - - const arg = Deno.args[0]; - - if (arg === "sync") { - await countries.sync({ force: true }); - } - - if (arg === "random") { - countries.print(countries.random()); - } - - if (arg === "find") { - countries.print(Deno.args[1]); + switch (command) { + case "sync": + await countries.sync({ force: true }); + break; + case "random": + countries.print(countries.random()); + break; + case "help": + help(); + break; + default: + countries.print(Deno.args.join(" ")); + break; } } diff --git a/src/countries.ts b/src/countries.ts index 895a93f..dba4d1a 100644 --- a/src/countries.ts +++ b/src/countries.ts @@ -48,12 +48,10 @@ export class Countries { } find(name: string): Country { - // Replace snake case or kebab case with whitespaces - name = name.toLowerCase().replace(/-|_/g, " "); - + name = name.toLowerCase(); // Find exact match first, then fall back to fuzzy match const country = this.list.find((c) => { - const countryName = c.name.common.toLocaleLowerCase(); + const countryName = c.name.common.toLowerCase(); return countryName === name || countryName.includes(name); }); @@ -80,15 +78,17 @@ export class Countries { let languages = []; for (const langAbbr in country.languages) { - languages.push(country.languages[langAbbr] + " "); + languages.push(country.languages[langAbbr]); } + // above code needs refactoring + console.log( nano.cyan("\nCountry:\t"), - country.flag, country.name.common, + country.flag, nano.green("\nLanguages:\t"), - ...languages, + languages.join(" | "), nano.green("\nCapital:\t"), country.capital[0], nano.green("\nRegion:\t\t"), diff --git a/src/environment/environment.ts b/src/environment/environment.ts index 0e29225..b3897ec 100644 --- a/src/environment/environment.ts +++ b/src/environment/environment.ts @@ -1,4 +1,4 @@ -import home_dir from "https://deno.land/x/dir/home_dir/mod.ts"; +import home_dir from "https://deno.land/x/[email protected]/home_dir/mod.ts"; import { join } from "https://deno.land/[email protected]/path/mod.ts"; export const environment = { diff --git a/src/util/help.ts b/src/util/help.ts new file mode 100644 index 0000000..e935f2c --- /dev/null +++ b/src/util/help.ts @@ -0,0 +1,24 @@ +export function help(): void { + console.log( + "\ncountryfetch\n", + "\tFetch information about countries", + "\n", + "\nUSAGE\n", + "\tcountryfetch <ARGS>", + "\n", + "\nARGS:\n", + "\tsync", + "\n\t\tSynchronize database. Stores countries' data in ~/.cache/conntryfetch/countries.json.", + "\n", + "\n\trandom", + "\n\t\tPrint information about a random country.", + "\n", + "\n\t<country_name>", + "\n\t\tPrint information about a specific country.", + "\n", + "\nEXAMPLE:\n", + "\tcountryfetch germany", + "\n\t\tPrints information about Germany", + "\n" + ); +} |
