UNPKG

@xtest-cli/cli

Version:

CLI for xtest.ing - AI-powered test generation platform

97 lines 5.32 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const chalk_1 = __importDefault(require("chalk")); const browser_1 = require("./commands/browser"); const auth_1 = require("./commands/auth"); const sessions_1 = require("./commands/sessions"); const dual_1 = require("./commands/dual"); const dual_v2_1 = require("./commands/dual-v2"); const dual_interactive_1 = require("./commands/dual-interactive"); const mirror_1 = require("./commands/mirror"); const package_json_1 = require("../package.json"); const config_1 = require("./utils/config"); const program = new commander_1.Command(); // Custom help display program.configureHelp({ sortSubcommands: true, subcommandTerm: (cmd) => cmd.name() + ' ' + cmd.usage(), }); program .name('xtest') .description('xtest CLI - Control browser automation sessions from your local machine') .version(package_json_1.version, '-v, --version', 'Display CLI version') .addHelpText('before', () => { return chalk_1.default.cyan('\n' + '═'.repeat(60)) + '\n' + chalk_1.default.cyan.bold(' xtest CLI') + chalk_1.default.gray(` v${package_json_1.version}`) + '\n' + chalk_1.default.cyan(' Browser Automation Made Simple') + '\n' + chalk_1.default.cyan('═'.repeat(60)) + '\n'; }) .addHelpText('after', () => { return '\n' + chalk_1.default.gray('For more information, visit: ') + chalk_1.default.cyan('https://xtest.ing/docs/cli') + '\n'; }); // Add commands program.addCommand(auth_1.authCommand); program.addCommand(browser_1.browserCommand); program.addCommand(sessions_1.sessionsCommand); program.addCommand(dual_1.dualCommand); program.addCommand(dual_v2_1.dual2Command); program.addCommand(dual_interactive_1.dualInteractiveCommand); program.addCommand(mirror_1.mirrorCommand); // Add global error handler program.exitOverride(); try { // Parse command line arguments program.parse(process.argv); } catch (err) { if (err.code === 'commander.unknownCommand') { console.error(chalk_1.default.red('\n❌ Unknown command: ') + chalk_1.default.yellow(err.message.split(':')[1].trim())); console.log(chalk_1.default.gray('\nRun ') + chalk_1.default.cyan('xtest --help') + chalk_1.default.gray(' to see available commands\n')); } else { console.error(chalk_1.default.red('\n❌ Error: ') + err.message + '\n'); } process.exit(1); } // Show enhanced help if no command provided if (!process.argv.slice(2).length) { (0, config_1.getConfig)().then(config => { const isAuthenticated = !!config.apiKey; console.log(chalk_1.default.cyan('\n' + '═'.repeat(60))); console.log(chalk_1.default.cyan.bold(' Welcome to xtest CLI!')); console.log(chalk_1.default.gray(' AI-powered browser automation & test generation')); console.log(); console.log(chalk_1.default.gray(' Version: ') + chalk_1.default.white(package_json_1.version)); console.log(chalk_1.default.gray(' Docs: ') + chalk_1.default.cyan('https://xtest.ing/docs/cli')); console.log(); if (!isAuthenticated) { console.log(chalk_1.default.yellow(' Quick Start:')); console.log(); console.log(chalk_1.default.white('Start a browser session:')); console.log(chalk_1.default.gray(' $ ') + chalk_1.default.white('xtest browser --mode headed')); console.log(chalk_1.default.white('Or use quick commands:')); console.log(chalk_1.default.gray(' $ ') + chalk_1.default.white('xtest auth') + chalk_1.default.gray(' # Login to your account')); console.log(chalk_1.default.gray(' $ ') + chalk_1.default.white('xtest sessions') + chalk_1.default.gray(' # List active sessions')); console.log(chalk_1.default.gray(' $ ') + chalk_1.default.white('xtest browser') + chalk_1.default.gray(' # Start a browser')); console.log(chalk_1.default.gray(' $ ') + chalk_1.default.white('xtest --help') + chalk_1.default.gray(' # Show all commands')); console.log(); } else { console.log(chalk_1.default.green('✅ You are authenticated!\n')); console.log(chalk_1.default.white('🚀 Start a browser session:')); console.log(chalk_1.default.cyan(' xtest browser --interactive\n')); console.log(chalk_1.default.white('📋 Or use quick commands:')); console.log(chalk_1.default.gray(' xtest browser ') + chalk_1.default.gray('# Start with defaults')); console.log(chalk_1.default.gray(' xtest browser --mode inspector ') + chalk_1.default.gray('# Debug mode')); console.log(chalk_1.default.gray(' xtest sessions list ') + chalk_1.default.gray('# View active sessions\n')); } console.log(chalk_1.default.gray('For all commands, run: ') + chalk_1.default.cyan('xtest --help')); console.log(chalk_1.default.gray('For command help, run: ') + chalk_1.default.cyan('xtest <command> --help\n')); }); } //# sourceMappingURL=index.js.map