import './GIS4KMDM.js';
import { volumeMappingSchema } from './ORWR6LWW.js';
import './6YTOLRHQ.js';
import './7BFNUKIW.js';
import { displayVersionCombinations, displayToolVersionInfo } from './3YHRHIKS.js';
import './Y27GTZ2Q.js';
import { compile } from './SV3LGPR3.js';
import { iotaWrapper } from './X72XTEFE.js';
import { buildTypescriptSdk } from './BTXB2LKA.js';
import { suiWrapper } from './362ZLRXL.js';
import './UKPHRO5A.js';
import './6QZPR4XG.js';
import { executeToolCommand } from './HCY4ASBG.js';
import './IWNVWC3I.js';
import './55HL3CFD.js';
import './FL2DFW3Y.js';
import './FQUILSS5.js';
import { tools, getToolDefaultVersion, getToolSupportedVersions } from './H7LPHZJT.js';
import './F35TPZS3.js';
import './D3JHHTB6.js';
import { init_esm_shims, __name } from './4RNWLMHM.js';
import { Command } from 'commander';
import { camelCase } from 'es-toolkit';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';

// src/index.ts
init_esm_shims();
var toolVersionOptions = Object.fromEntries(tools.map(({ name }) => [
  `${camelCase(name)}Version`,
  name
]));
var parseGlobalOptions = /* @__PURE__ */ __name((command) => {
  const { cwd, volume, ...options } = command.opts();
  return {
    ...options,
    cwd: cwd ?? process.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 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.argv.includes("--list-versions")) {
    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.isAbsolute(input)) {
      throw new Error("cwd must be an absolute path if provided");
    }
    if (!fs.existsSync(input)) {
      throw new Error("cwd does not exist");
    }
    if (!fs.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,
      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 tools) {
    const optionFlag = `--${tool.name}-version <version>`;
    const defaultVersion = getToolDefaultVersion(tool.name);
    const supportedVersions = 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) => displayToolVersionInfo(toolName));
  for (const tool of 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 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(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) => 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) => 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) => 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) => 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) => suiWrapper.run("test", args, parseGlobalOptions(program)));
  await program.parseAsync();
}
__name(run, "run");
var main = /* @__PURE__ */ __name(async () => {
  try {
    await run();
  } catch (error) {
    console.error("\u274C VM tool execution failed", error);
    process.exit(1);
  }
}, "main");

export { main };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map