aboutsummaryrefslogtreecommitdiff
path: root/src/app.ts
blob: 199446246ad60057ec97a4d6baca87c7a698ac3c (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
import { Countries } from "./countries.ts";
import { Logger } from "./util/logger.ts";

export class App {
  constructor(
    // private cache: Cache,
    private logger: Logger,
    private countries: Countries
  ) {}

  async run() {
    const command = Deno.args[0];

    await this.countries.sync();
    switch (command) {
      case undefined:
        this.logger.help();
        break;
      case "help":
        this.logger.help();
        break;
      case "sync":
        await this.countries.sync({
          force: true,
          flagAscii: Deno.args[1] === "flags",
        });
        break;
      case "random":
        await this.countries.print(this.countries.random());
        break;
      case "capital":
        const [, ...args] = Deno.args;
        const capital = args.join(" ");
        this.countries.capitalOf(capital);
        break;
      case "raw":
        this.logger.log(this.countries.find(Deno.args[1]));
        break;
      default:
        await this.countries.print(Deno.args.join(" "), true);
        break;
    }
  }
}