"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var chunk_TXQI3C4H_exports = {};
__export(chunk_TXQI3C4H_exports, {
  CLI: () => CLI
});
module.exports = __toCommonJS(chunk_TXQI3C4H_exports);
var import_chunk_SKRR5WT4 = require("./chunk-SKRR5WT4.js");
var import_internals = require("@prisma/internals");
var CLI = class _CLI {
  constructor(cmds) {
    this.cmds = cmds;
  }
  static new(cmds) {
    return new _CLI(cmds);
  }
  async parse(argv, config, baseDir) {
    const args = (0, import_internals.arg)(argv, {
      "--help": Boolean,
      "-h": "--help",
      "--config": String,
      "--json": Boolean,
      // for -v
      "--experimental": Boolean,
      "--preview-feature": Boolean,
      "--early-access": Boolean,
      "--telemetry-information": String
    });
    if ((0, import_internals.isError)(args)) {
      return this.help(args.message);
    }
    if (args._.length === 0 || args["--help"]) {
      return this.help();
    }
    const cmdName = args._[0];
    const cmd = this.cmds[cmdName];
    if (cmd) {
      let argsForCmd;
      if (args["--experimental"]) {
        argsForCmd = [...args._.slice(1), `--experimental=${args["--experimental"]}`];
      } else if (args["--preview-feature"]) {
        argsForCmd = [...args._.slice(1), `--preview-feature=${args["--preview-feature"]}`];
      } else if (args["--early-access"]) {
        argsForCmd = [...args._.slice(1), `--early-access=${args["--early-access"]}`];
      } else {
        argsForCmd = args._.slice(1);
      }
      return cmd.parse(argsForCmd, config, baseDir);
    }
    return (0, import_internals.unknownCommand)(this.help(), args._[0]);
  }
  help(error) {
    if (error) {
      return new import_internals.HelpError(`
${(0, import_chunk_SKRR5WT4.bold)((0, import_chunk_SKRR5WT4.red)(`!`))} ${error}
${_CLI.help}`);
    }
    return _CLI.help;
  }
  static help = (0, import_internals.format)(`This is the internal CLI for @prisma/migrate`);
};
