import './7DH3URRX.js';
import { displayVersionCombinations, displayToolVersionInfo } from './BA5XKPUD.js';
import './5OKX3IYN.js';
import './OAO7CCJW.js';
import { executeToolCommand } from './57KTFNRJ.js';
import './A7N65AYR.js';
import { tools, getToolDefaultVersion, getToolSupportedVersions } from './W2CW3JVG.js';
import './3CLGGUZ6.js';
import './MWXKZUMG.js';
import './HR64SZQX.js';
import './PDSRUQEX.js';
import { init_esm_shims, __name } from './4RNWLMHM.js';
import { Command } from 'commander';
import fs from 'fs';
import path from 'path';
import process from 'process';

// src/index.ts
init_esm_shims();
async function main() {
  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();
    process.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.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, 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;
  }, []);
  tools.forEach((tool) => {
    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);
  });
  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.cwd();
      try {
        await executeToolCommand(tool.name, args, {
          cwd,
          volumes: globalOptions.volume,
          ...globalOptions
        });
      } catch (error) {
        console.error(error instanceof Error ? error.message : String(error));
        process.exit(1);
      }
    });
  });
  await program.parseAsync();
}
__name(main, "main");
void main();
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map