#!/usr/bin/env node
import{parseArgs}from"node:util";import{ExitCode,Colors}from"./types.js";function showHelp(){console.log("\nxBind CLI - Identity-Based M2M Authentication\n\nUsage:\n  xbind <command> [options]\n\nCommands:\n  setup        Create deployment identity (DID + DeploymentID)\n  connect      Connect to a service (TODO)\n  invite       Generate viral invite link (TODO)\n  list         List all active connections (TODO)\n  status       Display connection status (TODO)\n  migrate      Scan codebase for API keys (TODO)\n  trial        Activate 3-month free trial (TODO)\n  deploy       Deploy proprietary algorithms (TODO)\n  server       Start agent relay server (TODO)\n  revoke       Revoke connection (TODO)\n  backup       Export/import identity (TODO)\n  debug        Diagnostic information (TODO)\n\nGlobal Options:\n  --json       Output JSON only (no human-readable text)\n  --no-color   Disable colored output\n  --debug      Show detailed error information\n  -h, --help   Show this help message\n\nExamples:\n  xbind setup --name my-service\n  xbind setup --email user@example.com --force\n  xbind connect payments-service\n  xbind status\n\nDocumentation:\n  https://private.me/docs/xbind\n  ".trim())}function showVersion(){console.log("xBind CLI v3.1.2")}async function main(){const e=process.argv.slice(2);if(0===e.length)return void showHelp();const{values:o,positionals:n}=parseArgs({args:e,options:{help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"},json:{type:"boolean"},"no-color":{type:"boolean"},debug:{type:"boolean"}},allowPositionals:!0,strict:!1});if(o.help)return void showHelp();if(o.version)return void showVersion();const t=n[0];if(t)switch(t){case"setup":{const{main:o}=await import("./setup.js");await o(e.slice(1));break}case"connect":case"invite":case"list":case"status":case"migrate":case"trial":case"deploy":case"server":case"revoke":case"backup":case"debug":{const e=!o["no-color"]&&process.stderr.isTTY,n=e?Colors.YELLOW:"",s=e?Colors.RESET:"";console.error(`${n}⚠️  Command "${t}" not yet implemented${s}`),console.error("\nAvailable commands:"),console.error("  • setup - Create deployment identity (IMPLEMENTED)"),console.error("\nComing soon: connect, invite, list, status, migrate, trial, deploy, server, revoke, backup, debug"),process.exit(ExitCode.USER_ERROR);break}default:{const e=!o["no-color"]&&process.stderr.isTTY,n=e?Colors.RED:"",s=e?Colors.RESET:"";console.error(`${n}❌ Error: Unknown command "${t}"${s}`),console.error('\nRun "xbind --help" to see available commands.'),process.exit(ExitCode.USER_ERROR)}}else showHelp()}main().catch(e=>{console.error("Fatal error:",e instanceof Error?e.message:String(e)),process.exit(ExitCode.SYSTEM_ERROR)});