Skip to content

Commit 4344293

Browse files
authored
Merge pull request #292 from smlx/improvements
improvements
2 parents a70a529 + 414537b commit 4344293

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ fuzz: mod-tidy generate
2828
cover: mod-tidy generate
2929
go test -v -count=1 -covermode=atomic -coverprofile=cover.out -coverpkg=./... ./...
3030
go tool cover -html=cover.out
31+
32+
.PHONY: docs
33+
docs:
34+
go run golang.org/x/pkgsite/cmd/pkgsite@latest -http=:8080

cmd/go-cli-github/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
package main
33

44
import (
5+
"context"
6+
"os"
7+
"os/signal"
8+
"syscall"
9+
510
"github.com/alecthomas/kong"
611
)
712

@@ -12,10 +17,14 @@ type CLI struct {
1217
}
1318

1419
func main() {
20+
ctx, stop := signal.NotifyContext(
21+
context.Background(), os.Interrupt, syscall.SIGTERM)
22+
defer stop()
1523
// parse CLI config
1624
cli := CLI{}
1725
kctx := kong.Parse(&cli,
1826
kong.UsageOnError(),
27+
kong.BindFor(ctx),
1928
)
2029
// execute CLI
2130
kctx.FatalIfErrorf(kctx.Run())

cmd/go-cli-github/serve.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"time"
67

@@ -11,7 +12,7 @@ import (
1112
type ServeCmd struct{}
1213

1314
// Run the serve command.
14-
func (*ServeCmd) Run() error {
15+
func (*ServeCmd) Run(ctx context.Context) error {
1516
fmt.Println(server.New(time.Now).Serve())
1617
return nil
1718
}

cmd/go-cli-github/version.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67
"runtime"
@@ -18,7 +19,7 @@ var (
1819
type VersionCmd struct{}
1920

2021
// Run the Version command.
21-
func (*VersionCmd) Run() error {
22+
func (*VersionCmd) Run(ctx context.Context) error {
2223
v, err := json.Marshal(
2324
struct {
2425
ProjectName string

0 commit comments

Comments
 (0)