export function parseArgs(argv) {
    const flags = {
        format: 'text',
        verbose: false,
        help: false,
        version: false,
        check: false,
        open: null,
        input: '',
        outDir: '',
        port: null,
        host: null,
        chart: '',
        domain: '',
        owner: '',
        queryOnly: false,
        template: '',
        connection: '',
        skipTests: false,
        save: false,
        force: false,
        http: false,
    };
    let command = null;
    let file = null;
    const rest = [];
    for (let i = 0; i < argv.length; i++) {
        const arg = argv[i];
        if (arg === '--help' || arg === '-h') {
            flags.help = true;
        }
        else if (arg === '--version' || arg === '-V') {
            flags.version = true;
        }
        else if (arg === '--verbose' || arg === '-v') {
            flags.verbose = true;
        }
        else if (arg === '--open') {
            flags.open = true;
        }
        else if (arg === '--no-open') {
            flags.open = false;
        }
        else if (arg === '--check') {
            flags.check = true;
        }
        else if (arg === '--format' && i + 1 < argv.length) {
            const fmt = argv[++i];
            if (fmt === 'json' || fmt === 'text')
                flags.format = fmt;
        }
        else if (arg === '--input' && i + 1 < argv.length) {
            flags.input = argv[++i];
        }
        else if (arg === '--out-dir' && i + 1 < argv.length) {
            flags.outDir = argv[++i];
        }
        else if (arg === '--to' && i + 1 < argv.length) {
            flags.to = argv[++i];
        }
        else if (arg === '--dry-run') {
            flags.dryRun = true;
        }
        else if (arg === '--plan') {
            flags.plan = true;
        }
        else if (arg === '--port' && i + 1 < argv.length) {
            const value = Number(argv[++i]);
            if (Number.isFinite(value) && value > 0) {
                flags.port = value;
            }
        }
        else if (arg === '--host' && i + 1 < argv.length) {
            flags.host = argv[++i];
        }
        else if (arg === '--chart' && i + 1 < argv.length) {
            flags.chart = argv[++i];
        }
        else if (arg === '--domain' && i + 1 < argv.length) {
            flags.domain = argv[++i];
        }
        else if (arg === '--owner' && i + 1 < argv.length) {
            flags.owner = argv[++i];
        }
        else if ((arg === '--template' || arg === '--pattern') && i + 1 < argv.length) {
            flags.template = argv[++i];
        }
        else if (arg === '--connection' && i + 1 < argv.length) {
            flags.connection = argv[++i];
        }
        else if (arg === '--query-only') {
            flags.queryOnly = true;
        }
        else if (arg === '--skip-tests') {
            flags.skipTests = true;
        }
        else if (arg === '--save') {
            flags.save = true;
        }
        else if (arg === '--force' || arg === '-f') {
            flags.force = true;
        }
        else if (arg === '--http') {
            flags.http = true;
        }
        else if (arg === '--from-draft' && i + 1 < argv.length) {
            flags.fromDraft = argv[++i];
        }
        else if (arg === '--contract' && i + 1 < argv.length) {
            flags.contract = argv[++i];
        }
        else if (arg === '--datalex-manifest' && i + 1 < argv.length) {
            flags.datalexManifestPath = argv[++i];
        }
        else if (arg === '--open-pr') {
            flags.openPr = true;
        }
        else if (arg === '--provider' && i + 1 < argv.length) {
            flags.provider = argv[++i];
        }
        else if (arg === '--user' && i + 1 < argv.length) {
            flags.user = argv[++i];
        }
        else if (arg === '--runtime-url' && i + 1 < argv.length) {
            flags.runtimeUrl = argv[++i];
        }
        else if (arg === '--runtime' && i + 1 < argv.length) {
            flags.runtime = argv[++i];
        }
        else if (arg === '--execute') {
            flags.execute = true;
        }
        else if (arg === '--ai') {
            flags.ai = true;
        }
        else if (arg === '--enterprise') {
            flags.enterprise = true;
        }
        else if (arg === '--ai-layout') {
            flags.aiLayout = true;
        }
        else if (arg === '--block' && i + 1 < argv.length) {
            flags.block = argv[++i];
        }
        else if (arg === '--question' && i + 1 < argv.length) {
            flags.question = argv[++i];
        }
        else if (arg === '--comment' && i + 1 < argv.length) {
            flags.comment = argv[++i];
        }
        else if (arg === '--min-route-accuracy' && i + 1 < argv.length) {
            const value = Number(argv[++i]);
            if (Number.isFinite(value) && value >= 0 && value <= 1)
                flags.minRouteAccuracy = value;
        }
        else if (arg === '--min-refusal' && i + 1 < argv.length) {
            const value = Number(argv[++i]);
            if (Number.isFinite(value) && value >= 0 && value <= 1)
                flags.minRefusal = value;
        }
        else if (arg === '--no-examples') {
            flags.noExamples = true;
        }
        else if (arg === '--impact') {
            flags.impact = true;
        }
        else if (!command) {
            command = arg;
        }
        else if (!file) {
            file = arg;
        }
        else {
            rest.push(arg);
        }
    }
    return { command, file, rest, flags };
}
//# sourceMappingURL=args.js.map