import { Command } from "commander"; import { Manager } from "../core/manager.ts"; import { listSoftwares } from "./commands/softwares.ts"; export class Cli { /** * CLI instance. * @protected */ protected command: Command; /** * Infernod manager instance. * @protected */ protected manager!: Manager; constructor() { this.command = new Command(); this.setup(); } /** * Run the currently passed command using the defined CLI. */ async run(): Promise { // Parse the provided command. await this.command.parseAsync(); } /** * Setup CLI commands, args and flags. * @protected */ protected setup(): void { this.command .name("infernod") .description("Infernod Manager CLI") .version("0.1.0") .option("-d, --database ", "set database path") // Boot the CLI using provided global options. .hook("preAction", async () => { await this.boot(); }); const softwares = this.command .command("softwares") .description("Softwares management commands."); softwares .command("list") .description("List all registered softwares.") .action(() => listSoftwares(this.manager)); } /** * Boot the CLI internal requirements. * Mainly, initialize the manager. * @protected */ protected boot(): Promise { this.manager = new Manager(); return this.manager.waitForInitialized(); } }