// cli/commands/estimate.ts — planu estimate <specId> (SPEC-124)
import { parseArgs } from 'node:util';
import { handleEstimate } from '../../tools/estimate.js';
import { formatToolResult } from '../formatter.js';
import { detectProjectId } from '../project-detector.js';
import { red } from '../colors.js';
export const estimateCommand = {
    name: 'estimate',
    description: 'Estimate effort for a spec',
    usage: 'planu estimate <specId> [--project-id ID]',
    async run(args, flags) {
        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: ${estimateCommand.usage}\n`);
            process.exitCode = 1;
            return;
        }
        const projectId = values['project-id'] ?? detectProjectId();
        const result = await handleEstimate({ specId, projectId });
        if (result.isError) {
            process.stderr.write(`${red(formatToolResult(result, flags))}\n`);
            process.exitCode = 1;
            return;
        }
        const output = formatToolResult(result, flags);
        if (output) {
            process.stdout.write(output + '\n');
        }
    },
};
//# sourceMappingURL=estimate.js.map