diff options
Diffstat (limited to 'src/app.ts')
| -rw-r--r-- | src/app.ts | 67 |
1 files changed, 36 insertions, 31 deletions
@@ -1,36 +1,41 @@ -import { green, cyan } from "https://deno.land/x/[email protected]/mod.ts"; import { Countries } from "./countries.ts"; -import { Cache } from "./util/cache.ts"; -import { help } from "./util/help.ts"; +import { Logger } from "./util/logger.ts"; -export async function app() { - const command = Deno.args[0]; - const countries = new Countries(new Cache()); +export class App { + constructor( + // private cache: Cache, + private logger: Logger, + private countries: Countries + ) {} - await countries.sync(); - switch (command) { - case undefined: - help(); - break; - case "help": - help(); - break; - case "sync": - await countries.sync({ force: true }); - break; - case "random": - countries.print(countries.random()); - break; - case "capital": - const [, ...args] = Deno.args; - const capital = args.join(" "); - const country = countries.findByCapital(capital); - console.log( - green(capital) + " is the capital of " + cyan(country.name.common) - ); - break; - default: - countries.print(Deno.args.join(" ")); - break; + 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 }); + break; + case "random": + 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: + this.countries.print(Deno.args.join(" ")); + break; + } } } |
