#!/usr/bin/env node
const { program } = require('commander');
const packageJson = require('../../package.json');
const { installCommand } = require('./commands/install');

program
  .name('rtexit')
  .description('RTExit CLI - AI-assisted Red Team methodology installer')
  .version(packageJson.version);

program
  .command('install')
  .description('Install RTExit into the current project')
  .action(() => installCommand());

// When run via npx with no args, auto-trigger install
const args = process.argv.slice(2);
const isNpx = process.env.npm_lifecycle_event === undefined && process.env.npm_execpath !== undefined;
const isDirectRun = args.length === 0;

if (isDirectRun) {
  // npx rtexit-method  OR  rtexit  → run install directly
  require('./commands/install').installCommand();
} else {
  program.parse(process.argv);
}
