// cli/commands/list.ts — planu list [--status approved] (SPEC-124)
import { parseArgs } from 'node:util';
import { handleListSpecs } from '../../tools/list-specs.js';
import { formatToolResult } from '../formatter.js';
import { detectProjectId } from '../project-detector.js';
import { red } from '../colors.js';
export const listCommand = {
    name: 'list',
    description: 'List specs in the current project',
    usage: 'planu list [--status draft] [--type feature] [--project-id ID]',
    async run(args, flags) {
        const { values } = parseArgs({
            args,
            options: {
                status: { type: 'string', short: 's' },
                type: { type: 'string', short: 't' },
                'project-id': { type: 'string' },
            },
            strict: false,
            allowPositionals: true,
        });
        const projectId = values['project-id'] ?? detectProjectId();
        const result = await handleListSpecs({
            projectId,
            status: values.status,
            type: values.type,
        });
        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=list.js.map