import { createInterface } from "node:readline/promises";
import { loadConfig, resolveConfigPath } from "../services/cli-config.js";
export function createPrompter(context) {
    let promptInterface;
    return {
        ask: async (question) => {
            if (context.prompt) {
                return context.prompt(question);
            }
            promptInterface ??= createInterface({ input: process.stdin, output: process.stdout });
            return promptInterface.question(question);
        },
        close: () => promptInterface?.close(),
    };
}
export async function loadCliState(context) {
    const configPath = resolveConfigPath(context.env);
    return { configPath, config: await loadConfig(configPath) };
}
export function parsedArgs(command, subject, positionals, options) {
    const flags = {};
    for (const [name, value] of Object.entries(options)) {
        if (value === undefined) {
            continue;
        }
        const flagName = name.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);
        if (value === false) {
            flags[`no-${flagName}`] = true;
        }
        else if (typeof value === "string" || typeof value === "boolean") {
            flags[flagName] = value;
        }
    }
    return { command, subject, positionals, flags };
}
//# sourceMappingURL=shared.js.map