diff --git a/Makefile b/Makefile index 2119f27..dac1c72 100644 --- a/Makefile +++ b/Makefile @@ -28,3 +28,7 @@ fuzz: mod-tidy generate cover: mod-tidy generate go test -v -count=1 -covermode=atomic -coverprofile=cover.out -coverpkg=./... ./... go tool cover -html=cover.out + +.PHONY: docs +docs: + go run golang.org/x/pkgsite/cmd/pkgsite@latest -http=:8080 diff --git a/cmd/go-cli-github/main.go b/cmd/go-cli-github/main.go index e7640b8..b6b0012 100644 --- a/cmd/go-cli-github/main.go +++ b/cmd/go-cli-github/main.go @@ -2,6 +2,11 @@ package main import ( + "context" + "os" + "os/signal" + "syscall" + "github.com/alecthomas/kong" ) @@ -12,10 +17,14 @@ type CLI struct { } func main() { + ctx, stop := signal.NotifyContext( + context.Background(), os.Interrupt, syscall.SIGTERM) + defer stop() // parse CLI config cli := CLI{} kctx := kong.Parse(&cli, kong.UsageOnError(), + kong.BindFor(ctx), ) // execute CLI kctx.FatalIfErrorf(kctx.Run()) diff --git a/cmd/go-cli-github/serve.go b/cmd/go-cli-github/serve.go index fe7016c..6e956fc 100644 --- a/cmd/go-cli-github/serve.go +++ b/cmd/go-cli-github/serve.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "time" @@ -11,7 +12,7 @@ import ( type ServeCmd struct{} // Run the serve command. -func (*ServeCmd) Run() error { +func (*ServeCmd) Run(ctx context.Context) error { fmt.Println(server.New(time.Now).Serve()) return nil } diff --git a/cmd/go-cli-github/version.go b/cmd/go-cli-github/version.go index f80aa88..8b42cc6 100644 --- a/cmd/go-cli-github/version.go +++ b/cmd/go-cli-github/version.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "fmt" "runtime" @@ -18,7 +19,7 @@ var ( type VersionCmd struct{} // Run the Version command. -func (*VersionCmd) Run() error { +func (*VersionCmd) Run(ctx context.Context) error { v, err := json.Marshal( struct { ProjectName string