/* eslint-disable no-console */ import { Command } from 'commander'; import chalk from 'chalk'; import { setApiKey } from '../utils/config.js'; export function createLoginCommand(): Command { return new Command('login') .description('Authenticate with your Rigstate API key') .argument('', 'Your Rigstate API key (starts with sk_)') .action(async (apiKey: string) => { try { // Basic validation if (!apiKey || !apiKey.startsWith('sk_rigstate_')) { console.error(chalk.red('āŒ Invalid API key format')); console.error(chalk.dim('API keys must start with "sk_rigstate_"')); process.exit(1); } // Store the API key setApiKey(apiKey); console.log(chalk.green('āœ… Successfully logged in!')); console.log( chalk.dim( `\nYour API key has been securely stored. You can now use "rigstate scan" to audit your code.` ) ); console.log(chalk.bold('\nšŸ¤– Cursor MCP Configuration')); console.log(chalk.dim('Copy and paste this into Cursor Settings -> Features -> MCP:')); console.log(chalk.cyan(` { "mcpServers": { "rigstate": { "command": "npx", "args": [ "-y", "@rigstate/mcp@latest" ], "env": { "RIGSTATE_API_KEY": "${apiKey}" } } } }`)); } catch (error) { console.error( chalk.red('āŒ Login failed:'), error instanceof Error ? error.message : 'Unknown error' ); process.exit(1); } }); }