package main

import (
	"fmt"
	"os"

	"github.com/wormhole/wormhole/internal/agent"
	"github.com/wormhole/wormhole/internal/server"
)

func main() {
	if len(os.Args) < 2 {
		printUsage()
		os.Exit(1)
	}

	cmd := os.Args[1]
	args := os.Args[2:]

	switch cmd {
	case "server", "serve", "s":
		server.Run(args)
	case "agent", "client", "a":
		agent.Run(args)
	case "help", "-h", "--help":
		printUsage()
	default:
		fmt.Fprintf(os.Stderr, "unknown command: %s\n\n", cmd)
		printUsage()
		os.Exit(1)
	}
}

func printUsage() {
	fmt.Fprintf(os.Stderr, `Wormhole — 内网穿透 / 反向代理（统一二进制）

用法:
  wormhole server                              启动服务端（配置在 Web 管理台）
  wormhole agent -server <地址> -key <verify_key>   启动客户端 Agent

简写:
  wormhole serve / wormhole s
  wormhole client / wormhole a

示例:
  wormhole server
  wormhole agent -server 127.0.0.1:8528 -key abc123

`)
}
