'use strict';

require('./7PP2QA5H.cjs');
var T7SZKDWZ_cjs = require('./T7SZKDWZ.cjs');
require('./FLI6L2YX.cjs');
require('./OOTZHKMN.cjs');
var PH3AB77Z_cjs = require('./PH3AB77Z.cjs');
require('./TYFYAP7W.cjs');
var DWHHPWIY_cjs = require('./DWHHPWIY.cjs');
require('./5RAWDGJY.cjs');
require('./EDZNH6J4.cjs');
require('./JJXZWB7K.cjs');
require('./NSZHKDNY.cjs');
var VO65XOWD_cjs = require('./VO65XOWD.cjs');
var commander = require('commander');
var fs = require('fs');
var path = require('path');
var process = require('process');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var fs__default = /*#__PURE__*/_interopDefault(fs);
var path__default = /*#__PURE__*/_interopDefault(path);
var process__default = /*#__PURE__*/_interopDefault(process);

// src/index.ts
VO65XOWD_cjs.init_cjs_shims();
async function main() {
  const program = new commander.Command();
  program.name("lz-tool").description("\u{1F680} LayerZero VM tooling with intelligent version management\n\nUsage pattern:\n  lz-tool [global-options] <tool> [tool-args...]\n\nExamples:\n  lz-tool -e bash sui --help\n  lz-tool --sui-version 1.38.0 sui client\n\nNote: All lz-tool options must appear BEFORE the tool name.").version("1.0.0").enablePositionalOptions();
  if (process__default.default.argv.includes("--list-versions")) {
    T7SZKDWZ_cjs.displayVersionCombinations();
    process__default.default.exit(0);
  }
  program.option("-c, --cwd <path>", "Current working directory", (input) => {
    if (typeof input !== "string") {
      throw new Error("cwd flag must be a string");
    }
    if (!path__default.default.isAbsolute(input)) {
      throw new Error("cwd must be an absolute path if provided");
    }
    if (!fs__default.default.existsSync(input)) {
      throw new Error("cwd does not exist");
    }
    if (!fs__default.default.statSync(input).isDirectory()) {
      throw new Error("cwd must be a directory");
    }
    return input;
  }).option("-e, --custom-entrypoint <entrypoint>", "Override the default Docker entrypoint for the tool").option("--script <script>", 'Execute a custom script using bash -c in the Docker container (e.g., --script "npm install && npm test")').option("--env <name=value>", "Set environment variables for Docker container (e.g., --env NODE_ENV=production)", (input, previous) => {
    const [name, ...valueParts] = input.split("=");
    if (name === "" || valueParts.length === 0) {
      throw new Error(`Invalid environment variable format: ${input}. Use --env NAME=VALUE`);
    }
    const value = valueParts.join("=");
    previous.push({
      name,
      value
    });
    return previous;
  }, []).option("-v, --volume <type:hostPath:containerPath[:name]>", "Volume mappings in the format type:hostPath:containerPath[:name] (e.g., host:/host/path:/container/path or isolate::/container/path:volumeName)", (input, previous) => {
    const [type, hostPath, containerPath, name] = input.split(":");
    if (type !== "host" && type !== "isolate") {
      throw new Error(`Invalid volume type: ${type}`);
    }
    if (type === "host" && (hostPath === void 0 || hostPath === "")) {
      throw new Error(`Host path is required for volume type 'host'`);
    }
    if (containerPath === void 0 || containerPath === "") {
      throw new Error(`Container path is required`);
    }
    previous.push({
      type,
      hostPath,
      containerPath,
      name
    });
    return previous;
  }, []);
  DWHHPWIY_cjs.tools.forEach((tool) => {
    const optionFlag = `--${tool.name}-version <version>`;
    const defaultVersion = DWHHPWIY_cjs.getToolDefaultVersion(tool.name);
    const supportedVersions = DWHHPWIY_cjs.getToolSupportedVersions(tool.name);
    const description = `Specify ${tool.name} version (default: ${defaultVersion}, supported: ${supportedVersions.join(", ")})`;
    program.option(optionFlag, description);
  });
  program.option("--list-versions", "Display all supported version combinations and exit");
  program.command("version-info <tool>").description("Display detailed version information for a specific tool").action((toolName) => {
    T7SZKDWZ_cjs.displayToolVersionInfo(toolName);
  });
  DWHHPWIY_cjs.tools.forEach((tool) => {
    const toolCmd = program.command(tool.name, {
      isDefault: false
    }).description(`Run ${tool.name} with version checking`).passThroughOptions(true).allowUnknownOption().helpOption(false).argument("[args...]", "Arguments to pass to the tool");
    toolCmd.action(async (args) => {
      const globalOptions = program.opts();
      const cwd = globalOptions.cwd ?? process__default.default.cwd();
      try {
        await PH3AB77Z_cjs.executeToolCommand(tool.name, args, {
          cwd,
          volumes: globalOptions.volume,
          ...globalOptions
        });
      } catch (error) {
        console.error(error instanceof Error ? error.message : String(error));
        process__default.default.exit(1);
      }
    });
  });
  await program.parseAsync();
}
VO65XOWD_cjs.__name(main, "main");
void main();
//# sourceMappingURL=index.cjs.map
//# sourceMappingURL=index.cjs.map