File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /dist
Original file line number Diff line number Diff line change 1+ builds :
2+ - main : ./cmd/go-cli-github
3+ ldflags :
4+ - >
5+ -s -w
6+ -X "main.commit={{.Commit}}"
7+ -X "main.date={{.Date}}"
8+ -X "main.goVersion={{.Env.GOVERSION}}"
9+ -X "main.projectName={{.ProjectName}}"
10+ -X "main.version={{.Version}}"
11+ env :
12+ - CGO_ENABLED=0
Original file line number Diff line number Diff line change 1+ # local development targets
2+
3+ .PHONY : test
4+ test : mod-tidy generate
5+ go test -v ./...
6+
7+ .PHONY : mod-tidy
8+ mod-tidy :
9+ go mod tidy
10+
11+ .PHONY : generate
12+ generate : mod-tidy
13+ go generate ./...
14+
15+ .PHONY : build
16+ build :
17+ GOVERSION=$$(go version ) goreleaser build --rm-dist --debug --snapshot
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "github.com/alecthomas/kong"
5+ )
6+
7+ var (
8+ commit string
9+ date string
10+ goVersion string
11+ projectName string
12+ version string
13+ )
14+
15+ // CLI represents the command-line interface.
16+ type CLI struct {
17+ Version VersionCmd `kong:"cmd,help='Print version information'"`
18+ }
19+
20+ func main () {
21+ // parse CLI config
22+ cli := CLI {}
23+ kctx := kong .Parse (& cli ,
24+ kong .UsageOnError (),
25+ )
26+ // execute CLI
27+ kctx .FatalIfErrorf (kctx .Run ())
28+ }
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "encoding/json"
5+ "fmt"
6+ )
7+
8+ // VersionCmd represents the `version` command.
9+ type VersionCmd struct {}
10+
11+ // Run the Version command.
12+ func (* VersionCmd ) Run () error {
13+ v , err := json .Marshal (
14+ struct {
15+ ProjectName string
16+ Version string
17+ Commit string
18+ BuildDate string
19+ GoVersion string
20+ }{
21+ projectName ,
22+ version ,
23+ commit ,
24+ date ,
25+ goVersion ,
26+ })
27+ if err != nil {
28+ return err
29+ }
30+ _ , err = fmt .Println (string (v ))
31+ return err
32+ }
Original file line number Diff line number Diff line change 1+ module github.com/smlx/go-cli-github
2+
3+ go 1.18
4+
5+ require github.com/alecthomas/kong v0.6.1
Original file line number Diff line number Diff line change 1+ github.com/alecthomas/kong v0.6.1 h1:1kNhcFepkR+HmasQpbiKDLylIL8yh5B5y1zPp5bJimA =
2+ github.com/alecthomas/kong v0.6.1 /go.mod h1:JfHWDzLmbh/puW6I3V7uWenoh56YNVONW+w8eKeUr9I =
3+ github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 h1:8Uy0oSf5co/NZXje7U1z8Mpep++QJOldL2hs/sBQf48 =
4+ github.com/alecthomas/repr v0.0.0-20210801044451-80ca428c5142 /go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8 =
5+ github.com/davecgh/go-spew v1.1.0 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
6+ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c =
7+ github.com/davecgh/go-spew v1.1.1 /go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38 =
8+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
9+ github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
10+ github.com/stretchr/objx v0.1.0 /go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME =
11+ github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s =
12+ github.com/stretchr/testify v1.7.2 /go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals =
13+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
14+ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA =
15+ gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
You can’t perform that action at this time.
0 commit comments