aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/cache.ts9
-rw-r--r--src/util/help.ts28
-rw-r--r--src/util/logger.ts77
3 files changed, 85 insertions, 29 deletions
diff --git a/src/util/cache.ts b/src/util/cache.ts
index 3a0c5d4..df52f89 100644
--- a/src/util/cache.ts
+++ b/src/util/cache.ts
@@ -1,5 +1,8 @@
import { join } from "https://deno.land/[email protected]/path/mod.ts";
-import { ensureDirSync } from "https://deno.land/[email protected]/fs/mod.ts";
+import {
+ ensureDirSync,
+ existsSync,
+} from "https://deno.land/[email protected]/fs/mod.ts";
import { environment } from "../environment/environment.ts";
export class Cache {
@@ -36,4 +39,8 @@ export class Cache {
return undefined;
}
}
+
+ public exists(name: string, extension?: string) {
+ return existsSync(join(this.path, `${name}${extension}`));
+ }
}
diff --git a/src/util/help.ts b/src/util/help.ts
deleted file mode 100644
index 80b7e57..0000000
--- a/src/util/help.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-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 the specified country.",
- "\n",
- "\n",
- "\n\tcapital <capital>",
- "\n\t\tPrint country to which the specified capital belongs.",
- "\n",
- "\nEXAMPLE:\n",
- "\tcountryfetch germany",
- "\n\t\tPrints information about Germany",
- "\n"
- );
-}
diff --git a/src/util/logger.ts b/src/util/logger.ts
new file mode 100644
index 0000000..52965c8
--- /dev/null
+++ b/src/util/logger.ts
@@ -0,0 +1,77 @@
+import * as nano from "https://deno.land/x/[email protected]/mod.ts";
+import { FetchedCountry } from "../models/FetchedCountry.model.ts";
+
+export class Logger {
+ public log(...data: any) {
+ console.log(data);
+ }
+
+ public alert(...data: any) {
+ console.log(nano.yellow(data));
+ }
+
+ public success(...data: any) {
+ console.log(nano.green(data));
+ }
+
+ public error(...data: any) {
+ console.error(data);
+ }
+
+ public logCountry(country: FetchedCountry) {
+ console.log(
+ nano.cyan("\nCountry:\t"),
+ country.country,
+ country.flag,
+ nano.green("\nLanguages:\t"),
+ country.languages,
+ nano.green("\nCapital:\t"),
+ country.capital,
+ nano.green("\nRegion:\t\t"),
+ country.region,
+ nano.green("\nPopulation:\t"),
+ country.population.toLocaleString(),
+ nano.green("\nCurrencies:\t"),
+ country.currencies
+ );
+ }
+
+ public capitalOf(capital: string, country: string) {
+ console.log(
+ nano.green(capital) + " is the capital of " + nano.cyan(country)
+ );
+ }
+
+ public 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 the specified country.",
+ "\n",
+ "\n",
+ "\n\tcapital <capital>",
+ "\n\t\tPrint country to which the specified capital belongs.",
+ "\n",
+ "\n",
+ "\n\traw <country_name>",
+ "\n\t\tPrint country information in raw format as JavaScript object.",
+ "\n",
+ "\nEXAMPLE:\n",
+ "\tcountryfetch germany",
+ "\n\t\tPrints information about Germany.",
+ "\n"
+ );
+ }
+}