#!/usr/bin/env node

const { spawnSync } = require('child_process');

// Try uvx first (fastest), then pipx as fallback
const runners = [
  { cmd: 'uvx', args: ['cube-mcp'] },
  { cmd: 'pipx', args: ['run', 'cube-mcp'] },
];

for (const { cmd, args } of runners) {
  const result = spawnSync(cmd, args, {
    stdio: 'inherit',
    shell: process.platform === 'win32',
  });

  // If command was found (even if it failed), exit with its status
  if (result.error?.code !== 'ENOENT') {
    process.exit(result.status || 0);
  }
}

// Neither runner found - show installation instructions
console.error(`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
cube-mcp requires 'uv' or 'pipx' to run Python packages.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Install uv (recommended - fast Python package manager):

  curl -LsSf https://astral.sh/uv/install.sh | sh

Or install pipx:

  macOS:   brew install pipx && pipx ensurepath
  Linux:   pip install --user pipx && pipx ensurepath
  Windows: pip install pipx

Then restart your terminal and try again:

  npx cube-mcp

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
`);
process.exit(1);
