// cli/commands/validate.ts — planu validate <specId> (SPEC-124)
import { parseArgs } from 'node:util';
import { handleValidate } from '../../tools/validate.js';
import { formatToolResult } from '../formatter.js';
import { detectProjectId } from '../project-detector.js';
import { red } from '../colors.js';
export const validateCommand = {
    name: 'validate',
    description: 'Validate a spec against its codebase',
    usage: 'planu validate <specId> [--project-id ID]',
    async run(args) {
        const { values, positionals } = parseArgs({
            args,
            options: {
                'project-id': { type: 'string' },
            },
            strict: false,
            allowPositionals: true,
        });
        const specId = positionals[0];
        if (!specId) {
            process.stderr.write(`${red('Error:')} Spec ID is required.\nUsage: ${validateCommand.usage}\n`);
            process.exitCode = 1;
            return;
        }
        const projectId = values['project-id'] ?? detectProjectId();
        const result = await handleValidate({ specId, projectId });
        if (result.isError) {
            process.stderr.write(`${red(formatToolResult(result))}\n`);
            process.exitCode = 1;
            return;
        }
        process.stdout.write(formatToolResult(result) + '\n');
    },
};
//# sourceMappingURL=validate.js.map