aboutsummaryrefslogtreecommitdiff
path: root/src/util/logger.ts
blob: ebf4ad14a942c9ac60fc8e44569977a9cbba3f65 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import * as nano from "https://deno.land/x/[email protected]/mod.ts";
import { FetchedCountry } from "../models/fetched-country.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(nano.red(data));
  }

  public progress(
    current: number,
    total: number,
    config?: { title?: string; description: string }
  ) {
    console.clear();
    if (config?.title) {
      this.alert(config.title);
    }
    console.log(`${current}/${total} ${config?.description || ""}`);
  }

  public logCountry(country: FetchedCountry) {
    console.log(
      nano.cyan("Country:"),
      country.country,
      country.flag,
      nano.green("\nLat/Lng:"),
      country.latlng,
      nano.green("\nPopulation:"),
      country.population,
      nano.green("\nLanguages:"),
      country.languages,
      nano.green("\nCapital:"),
      country.capital,
      nano.green("\nCapital Lat/Lng:"),
      country.capitalLatLng,
      nano.green("\nRegion:"),
      country.region,
      nano.green("\nSubregion:"),
      country.subregion,
      nano.green("\nTimezones:"),
      country.timezones,
      nano.green("\nTop Level Domain:"),
      country.tld,
      nano.green("\nCurrencies:"),
      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/countryfetch/countries.json.",
      "\n\t\tPass additional argument 'sync flags' to fetch and convert flags in ASCII art.",
      "\n\t\tAfter syncing flags, every countryfetch command will display flag ASCII art.",
      "\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"
    );
  }
}