aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFridon <[email protected]>2022-06-21 22:56:51 +0400
committerFridon <[email protected]>2022-06-21 22:56:51 +0400
commit9e941040b9e3e16b05c3e5309619e5885de183a1 (patch)
tree8d16bd4e35f81ae72c9a4cda6c9750ef76f4ab8e
parent5f17dfba0040b240f7d79f12420331ae62071bfb (diff)
downloadcountryfetch-9e941040b9e3e16b05c3e5309619e5885de183a1.tar.xz
countryfetch-9e941040b9e3e16b05c3e5309619e5885de183a1.zip
fix search limitation, add help option and minor changes
-rw-r--r--README.md17
-rw-r--r--images/countryfetch.pngbin400061 -> 1595036 bytes
-rwxr-xr-xinstall.sh2
-rwxr-xr-xrun.sh4
-rw-r--r--src/app.ts28
-rw-r--r--src/countries.ts14
-rw-r--r--src/environment/environment.ts2
-rw-r--r--src/util/help.ts24
8 files changed, 59 insertions, 32 deletions
diff --git a/README.md b/README.md
index 6732440..0afed34 100644
--- a/README.md
+++ b/README.md
@@ -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
index cdcac7d..46eedc1 100644
--- a/images/countryfetch.png
+++ b/images/countryfetch.png
Binary files differ
diff --git a/install.sh b/install.sh
index e40e384..1b48f03 100755
--- a/install.sh
+++ b/install.sh
@@ -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
diff --git a/run.sh b/run.sh
new file mode 100755
index 0000000..ee6de8f
--- /dev/null
+++ b/run.sh
@@ -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
diff --git a/src/app.ts b/src/app.ts
index 87aa8bb..5edccbe 100644
--- a/src/app.ts
+++ b/src/app.ts
@@ -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"
+ );
+}