// cli/commands/create.ts — planu create <title> [--type feature] (SPEC-124)
import { parseArgs } from 'node:util';
import { resolve } from 'node:path';
import { handleCreateSpec } from '../../tools/create-spec.js';
import { formatToolResult } from '../formatter.js';
import { green, red } from '../colors.js';
export const createCommand = {
    name: 'create',
    description: 'Create a new spec',
    usage: 'planu create <title> [--type feature] [--description "..."] [--path .]',
    async run(args) {
        const { values, positionals } = parseArgs({
            args,
            options: {
                type: { type: 'string', short: 't' },
                description: { type: 'string', short: 'd' },
                path: { type: 'string', short: 'p' },
                scope: { type: 'string' },
                target: { type: 'string' },
                feature: { type: 'string' },
            },
            strict: false,
            allowPositionals: true,
        });
        const title = positionals.join(' ');
        if (!title) {
            process.stderr.write(`${red('Error:')} Title is required.\nUsage: ${createCommand.usage}\n`);
            process.exitCode = 1;
            return;
        }
        const projectPath = resolve(values.path ?? process.cwd());
        const description = values.description ?? title;
        const result = await handleCreateSpec({
            title,
            description,
            projectPath,
            type: values.type,
            scope: values.scope,
            target: values.target,
            feature: values.feature ?? undefined,
        });
        if (result.isError) {
            process.stderr.write(`${red(formatToolResult(result))}\n`);
            process.exitCode = 1;
            return;
        }
        process.stdout.write(`${green('Spec created!')} ${formatToolResult(result)}\n`);
    },
};
//# sourceMappingURL=create.js.map