infernod/cli/cli.ts

67 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

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<void> {
// 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 <string>", "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<void> {
this.manager = new Manager();
return this.manager.waitForInitialized();
}
}