index.ts•2.55 kB
#!/usr/bin/env node
/**
* WhaTap MXQL CLI - Main Entry Point
*/
import { Command } from 'commander';
import chalk from 'chalk';
import { loginCommand } from './commands/login';
import { logoutCommand } from './commands/logout';
import { projectsCommand } from './commands/projects';
import { queryCommand } from './commands/query';
import { interactiveCommand } from './commands/interactive';
const program = new Command();
program
.name('whatap-mxql')
.description('WhaTap MXQL CLI - Query WhaTap monitoring data using MXQL')
.version('1.0.0');
// Login command
program
.command('login')
.description('Login to WhaTap service')
.option('-e, --email <email>', 'WhaTap account email')
.option('-p, --password <password>', 'WhaTap account password')
.option('-u, --url <url>', 'WhaTap service URL')
.action(loginCommand);
// Logout command
program
.command('logout')
.description('Logout and clear stored session')
.action(logoutCommand);
// Projects command
program
.command('projects')
.description('List all accessible projects')
.option('-f, --format <format>', 'Output format (table|json|csv)', 'table')
.option('--filter <type>', 'Filter by product type (BROWSER|MOBILE|APM|etc)')
.action(projectsCommand);
// Query command
program
.command('query')
.description('Execute MXQL query')
.argument('<pcode>', 'Project code')
.argument('[mxql]', 'MXQL query string (or use -f to read from file)')
.option('-f, --file <path>', 'Read MXQL query from file')
.option('-s, --start <time>', 'Start time (ISO string or timestamp)')
.option('-e, --end <time>', 'End time (ISO string or timestamp)')
.option('-r, --range <range>', 'Time range preset (1h|6h|24h|7d|30d)', '1h')
.option('-l, --limit <number>', 'Result limit', '100')
.option('-o, --output <format>', 'Output format (table|json|csv)', 'table')
.option('--no-header', 'Exclude header row in output')
.action(queryCommand);
// Interactive mode
program
.command('interactive')
.alias('i')
.description('Start interactive REPL mode')
.option('-p, --project <pcode>', 'Default project code')
.action(interactiveCommand);
// Error handler
program.exitOverride((err) => {
if (err.code === 'commander.help') {
process.exit(0);
}
if (err.code === 'commander.version') {
process.exit(0);
}
console.error(chalk.red('Error:'), err.message);
process.exit(1);
});
// Parse arguments
program.parse(process.argv);
// Show help if no command provided
if (!process.argv.slice(2).length) {
program.outputHelp();
}