import "reflect-metadata";
import { config } from "dotenv";

config();

import Vorpal from "vorpal";

import { NestFactory } from "@nestjs/core";
import { AppModule } from "../app.module";

const vorpal = new Vorpal();

async function main() {
  const app = await NestFactory.createApplicationContext(AppModule, {
    logger: false,
  });

  try {
    // registerCommands(vorpal, { app });

    const args = process.argv.slice(2);
    if (args.length > 0) {
      await vorpal.exec(args.join(" "));
    } else {
      vorpal.parse(process.argv);
    }
  } finally {
    await app.close();
  }
}

main().catch((err) => {
  console.error("Script failed:", err);
  process.exit(1);
});
