#!/usr/bin/env node
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
{
    const existingWarningListeners = process.listeners('warning');
    process.removeAllListeners('warning');
    process.on('warning', (warning) => {
        if (warning.name === 'DeprecationWarning') {
            return;
        }
        for (const handler of existingWarningListeners) {
            handler(warning);
        }
    });
}
const path_1 = __importDefault(require("path"));
const bundledDir = path_1.default.resolve(__dirname, '_bundled');
if (!process.env.NODE_PATH?.includes(bundledDir)) {
    process.env.NODE_PATH = process.env.NODE_PATH
        ? `${process.env.NODE_PATH}${path_1.default.delimiter}${bundledDir}`
        : bundledDir;
    require('module').Module._initPaths();
}
{
    const fs = require('fs');
    const bundledMobileRuntime = path_1.default.join(bundledDir, '@mablhq-internal/mobile-runtime');
    const mobileRuntime = require(fs.existsSync(bundledMobileRuntime)
        ? bundledMobileRuntime
        : '@mablhq-internal/mobile-runtime');
    mobileRuntime.registerMobilePlatform();
}
const yargs = __importStar(require("yargs"));
const env_1 = require("@mablhq-internal/runtime/env/env");
const constants_1 = require("./commands/constants");
const constants_2 = require("@mablhq-internal/runtime/core/constants");
const middleware_1 = require("./middleware");
const fs_1 = __importDefault(require("fs"));
process.setMaxListeners(20);
require('yargonaut').style('cyan').helpStyle('magenta').errorsStyle('red');
const internalCommandsAvailable = fs_1.default.existsSync(path_1.default.resolve(__dirname, 'commands', 'internal'));
const cli = yargs
    .scriptName(env_1.SCRIPT_NAME)
    .commandDir('./commands/agent')
    .commandDir('./commands/applications')
    .commandDir('./commands/auth')
    .commandDir('./commands/branches')
    .commandDir('./commands/config')
    .commandDir('./commands/credentials')
    .commandDir('./commands/databases')
    .commandDir('./commands/datatables')
    .commandDir('./commands/deploy')
    .commandDir('./commands/environments')
    .commandDir('./commands/flows');
if (internalCommandsAvailable) {
    cli.commandDir('./commands/internal');
}
cli
    .commandDir('./commands/link-agents')
    .commandDir('./commands/mobile-build-files')
    .commandDir('./commands/plans')
    .commandDir('./commands/tests')
    .commandDir('./commands/test-runs')
    .commandDir('./commands/users')
    .commandDir('./commands/workspaces')
    .commandDir('./commands/agent')
    .commandDir('./commands/agent-instructions')
    .commandDir('./commands/mcp')
    .demandCommand(1, '')
    .recommendCommands()
    .strict()
    .help(constants_2.CommandArgHelp)
    .alias(constants_2.CommandArgHelp, constants_1.CommandArgAliases.ShowHelp)
    .alias(constants_1.CommandArgVersion, constants_1.CommandArgAliases.Version)
    .wrap(null)
    .epilogue('Read full docs @ https://help.mabl.com/docs/mabl-cli')
    .middleware(middleware_1.CLI_MIDDLEWARE).argv;
