package main

import (
	"context"
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"github.com/alecthomas/kong"
	"tuxpa.in/a/pprofweb/cli"
)

func main() {
	ctx := NewCLI()
	sctx, cn := signal.NotifyContext(context.Background(), os.Kill, syscall.SIGTERM, syscall.SIGILL)
	defer cn()
	if err := ctx.Run(cli.Context{Context: sctx}); err != nil {
		fmt.Fprintf(os.Stderr, "error: %v\n", err)
		os.Exit(1)
	}
}

func NewCLI() *kong.Context {
	ctx := kong.Parse(&cli.CLI)
	return ctx
}