hatch-surf/cmd/hatch/main.go
SoftwareEngineer 60e25bfc9d feat: add thin CLI for Hatch
Implements CLI commands that wrap the JSON API layer:
- hatch capture <url> - Send request to endpoint and store it
- hatch inspect <endpoint> - Fetch requests as JSON
- hatch search <endpoint> - Search captured traffic
- hatch replay <request-id> - Replay a captured request
- hatch mock set <endpoint> - Configure mock response
- hatch doc generate <endpoint> - Output OpenAPI spec

Uses stdlib flag package for CLI parsing (boring tools philosophy).
All commands talk to running Hatch server via HTTP.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-23 09:59:38 +02:00

42 lines
796 B
Go

package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/elfoundation/hatch/internal/handler"
"github.com/elfoundation/hatch/internal/store"
"github.com/go-chi/chi/v5"
)
func main() {
// CLI mode: if a subcommand is provided, handle it and exit.
if cliMain() {
return
}
// Server mode: start the HTTP server.
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
dbPath := os.Getenv("HATCH_DB_PATH")
repo, err := store.Open(dbPath)
if err != nil {
log.Fatalf("hatch: open store: %v", err)
}
defer repo.Close()
h := handler.New(repo)
r := chi.NewRouter()
h.RegisterRoutes(r)
addr := fmt.Sprintf(":%s", port)
log.Printf("hatch starting on %s", addr)
if err := http.ListenAndServe(addr, r); err != nil {
log.Fatalf("hatch server error: %v", err)
}
}