'use strict';

require('./IDMMHZJ3.cjs');
var LNCARCBD_cjs = require('./LNCARCBD.cjs');
require('./S3PHE6F2.cjs');
require('./CYUSPBTH.cjs');
var ZD3LAY33_cjs = require('./ZD3LAY33.cjs');
require('./M6KBN6B2.cjs');
var VPSZX4TV_cjs = require('./VPSZX4TV.cjs');
var GJ24YLYE_cjs = require('./GJ24YLYE.cjs');
var DB5GRF5K_cjs = require('./DB5GRF5K.cjs');
var QU36PNBP_cjs = require('./QU36PNBP.cjs');
require('./L2LY6RIT.cjs');
require('./Z253B63X.cjs');
var BRSAP7LG_cjs = require('./BRSAP7LG.cjs');
require('./YNMZEV5X.cjs');
require('./ACDTMA6Q.cjs');
require('./6NIOUVPA.cjs');
require('./36UU6CJU.cjs');
var FOFSZBOK_cjs = require('./FOFSZBOK.cjs');
require('./PUL6NSHI.cjs');
require('./KSZMBVFB.cjs');
var U7VZULNU_cjs = require('./U7VZULNU.cjs');
var commander = require('commander');
var esToolkit = require('es-toolkit');
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
U7VZULNU_cjs.init_cjs_shims();
var toolVersionOptions = Object.fromEntries(FOFSZBOK_cjs.tools.map(({ name }) => [
  `${esToolkit.camelCase(name)}Version`,
  name
]));
var parseGlobalOptions = /* @__PURE__ */ U7VZULNU_cjs.__name((command) => {
  const { cwd, volume, ...options } = command.opts();
  return {
    ...options,
    cwd: cwd ?? process__default.default.cwd(),
    volumes: volume,
    versions: Object.fromEntries(Object.entries(options).map(([name, version]) => [
      toolVersionOptions[name],
      version
    ]).filter(([tool]) => tool))
  };
}, "parseGlobalOptions");
async function run() {
  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")) {
    ZD3LAY33_cjs.displayVersionCombinations();
    return;
  }
  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, variables) => {
    const [name, ...valueParts] = input.split("=");
    if (!name || !valueParts.length) {
      throw new Error(`Invalid environment variable format: ${input}. Use --env NAME=VALUE`);
    }
    return [
      ...variables,
      {
        name,
        value: valueParts.join("=")
      }
    ];
  }, []).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, volumes) => {
    const [type, hostPath, containerPath, name] = input.split(":");
    switch (type) {
      case "host":
        if (!hostPath) {
          throw new Error(`Host path is required for volume type 'host'`);
        }
        break;
      case "isolate":
        if (!name) {
          throw new Error(`Name is required for volume type 'isolate'`);
        }
        break;
      default:
        throw new Error(`Invalid volume type: ${type}`);
    }
    if (!containerPath) {
      throw new Error(`Container path is required`);
    }
    return [
      ...volumes,
      LNCARCBD_cjs.volumeMappingSchema.parse({
        type,
        hostPath,
        containerPath,
        name
      })
    ];
  }, []).option("-p, --publish <host_port:container_port>", "Publish a container's port(s) to the host");
  for (const tool of FOFSZBOK_cjs.tools) {
    const optionFlag = `--${tool.name}-version <version>`;
    const defaultVersion = FOFSZBOK_cjs.getToolDefaultVersion(tool.name);
    const supportedVersions = FOFSZBOK_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) => ZD3LAY33_cjs.displayToolVersionInfo(toolName));
  for (const tool of FOFSZBOK_cjs.tools) {
    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").action(async (args) => {
      await BRSAP7LG_cjs.executeToolCommand(tool.name, args, parseGlobalOptions(program));
    });
  }
  const extra = program.command("extra").description("Extra commands for VM tooling");
  extra.command("starknet").command("build-typescript-sdk").description("Generate TypeScript SDK for Starknet").argument("<package-name>", "Scarb package name").argument("<target-directory>", "Scarb target directory").argument("<src-directory>", "TypeScript source directory").action(DB5GRF5K_cjs.buildTypescriptSdk);
  const aptos = extra.command("aptos");
  aptos.command("compile").description("Compile Aptos contracts and generate the module order file").argument("[args...]", "Arguments to pass to `aptos move compile` command").passThroughOptions(true).allowUnknownOption().action((args) => VPSZX4TV_cjs.compile(args, parseGlobalOptions(program)));
  const iota = extra.command("iota");
  iota.command("build").description("Build IOTA contracts with shared dependency and configuration Docker volumes").argument("[args...]", "Arguments to pass to `iota move build` command").passThroughOptions(true).allowUnknownOption().action((args) => GJ24YLYE_cjs.iotaWrapper.run("build", args, parseGlobalOptions(program)));
  iota.command("test").description("Test IOTA contracts with shared dependency and configuration Docker volumes").argument("[args...]", "Arguments to pass to `iota move test` command").passThroughOptions(true).allowUnknownOption().action((args) => GJ24YLYE_cjs.iotaWrapper.run("test", args, parseGlobalOptions(program)));
  const sui = extra.command("sui");
  sui.command("build").description("Build Sui contracts with shared dependency and configuration Docker volumes").argument("[args...]", "Arguments to pass to `sui move build` command").passThroughOptions(true).allowUnknownOption().action((args) => QU36PNBP_cjs.suiWrapper.run("build", args, parseGlobalOptions(program)));
  sui.command("test").description("Test Sui contracts with shared dependency and configuration Docker volumes").argument("[args...]", "Arguments to pass to `sui move test` command").passThroughOptions(true).allowUnknownOption().action((args) => QU36PNBP_cjs.suiWrapper.run("test", args, parseGlobalOptions(program)));
  await program.parseAsync();
}
U7VZULNU_cjs.__name(run, "run");
var main = /* @__PURE__ */ U7VZULNU_cjs.__name(async () => {
  try {
    await run();
  } catch (error) {
    console.error("\u274C VM tool execution failed", error);
    process__default.default.exit(1);
  }
}, "main");

exports.main = main;
//# sourceMappingURL=index.cjs.map
//# sourceMappingURL=index.cjs.map