Skip to content

Commit

Permalink
✨ embedded version and revision
Browse files Browse the repository at this point in the history
  • Loading branch information
budougumi0617 committed Jan 11, 2021
1 parent 3dacecf commit 4183179
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ before:
builds:
-
main: ./cmd/nrseg
ldflags:
- -s -w
- -X nrseg.Version={{.Version}}
- -X nrseg.Revision={{.ShortCommit}}
env:
- CGO_ENABLED=0
archives:
Expand Down
13 changes: 11 additions & 2 deletions nrseg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var (
)

var (
version = "dev"
Version = "devel"
Revision = "unset"
)

type nrseg struct {
Expand All @@ -32,6 +33,14 @@ func fill(args []string, outStream, errStream io.Writer) (*nrseg, error) {
cn := args[0]
flags := flag.NewFlagSet(cn, flag.ContinueOnError)
flags.SetOutput(errStream)
flags.Usage = func() {
fmt.Fprintf(
flag.CommandLine.Output(),
"Insert function segments into any function/method for Newrelic APM.\n\nUsage of %s:\n",
os.Args[0],
)
flags.PrintDefaults()
}

var v bool
vdesc := "print version information and quit."
Expand All @@ -47,7 +56,7 @@ func fill(args []string, outStream, errStream io.Writer) (*nrseg, error) {
return nil, err
}
if v {
fmt.Fprintf(errStream, "%s version %s\n", cn, version)
fmt.Fprintf(errStream, "%s version %q, revison %q\n", cn, Version, Revision)
return nil, ErrShowVersion
}

Expand Down

0 comments on commit 4183179

Please sign in to comment.