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 9bd551a commit 7dacf04
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 1 addition & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ builds:
-
main: ./cmd/nrseg
ldflags:
- -s -w
- -X nrseg.Version={{.Version}}
- -X nrseg.Revision={{.ShortCommit}}
- -s -w -X main.Version={{.Version}} -X main.Revision={{.ShortCommit}}
env:
- CGO_ENABLED=0
archives:
Expand Down
7 changes: 6 additions & 1 deletion cmd/nrseg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import (
"github.com/budougumi0617/nrseg"
)

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

func main() {
if err := nrseg.Run(os.Args, os.Stdout, os.Stderr); err != nil {
if err := nrseg.Run(os.Args, os.Stdout, os.Stderr, Version, Revision); err != nil {
os.Exit(1)
}
}
13 changes: 4 additions & 9 deletions nrseg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@ var (
ErrShowVersion = errors.New("show version")
)

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

type nrseg struct {
in, dist string
ignoreDirs []string
outStream, errStream io.Writer
}

func fill(args []string, outStream, errStream io.Writer) (*nrseg, error) {
func fill(args []string, outStream, errStream io.Writer, version, revision string) (*nrseg, error) {
cn := args[0]
flags := flag.NewFlagSet(cn, flag.ContinueOnError)
flags.SetOutput(errStream)
Expand All @@ -56,7 +51,7 @@ func fill(args []string, outStream, errStream io.Writer) (*nrseg, error) {
return nil, err
}
if v {
fmt.Fprintf(errStream, "%s version %q, revison %q\n", cn, Version, Revision)
fmt.Fprintf(errStream, "%s version %q, revison %q\n", cn, version, revision)
return nil, ErrShowVersion
}

Expand Down Expand Up @@ -168,8 +163,8 @@ func (n *nrseg) writeOtherPath(in, dist, path string, got []byte) error {
}

// Run is entry point.
func Run(args []string, outStream, errStream io.Writer) error {
nrseg, err := fill(args, outStream, errStream)
func Run(args []string, outStream, errStream io.Writer, version, revision string) error {
nrseg, err := fill(args, outStream, errStream, version, revision)
if err != nil {
return err
}
Expand Down

0 comments on commit 7dacf04

Please sign in to comment.