Skip to content

Commit

Permalink
Merge pull request #71 from catatsuy/feature_use_debug_read_build_info
Browse files Browse the repository at this point in the history
use debug.ReadBuildInfo
  • Loading branch information
catatsuy authored Dec 19, 2020
2 parents 0279dc0 + d497f77 commit 5755fb8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.14.x' ]
go: [ '1.15.x' ]
steps:

- name: Set up Go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.14
go-version: 1.15
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ builds:
binary: notify_slack
ldflags:
- -s -w
- -X github.com/catatsuy/notify_slack/cli.Version={{.Version}}
- -X github.com/catatsuy/notify_slack/cli.Version=v{{.Version}}
env:
- CGO_ENABLED=0
goarch:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ If you have a development environment for the Go language, you can compile and i
GO111MODULE=on go get github.com/catatsuy/notify_slack/cmd/notify_slack
```

If you want to develop it, you can use the `make`. It requires Go 1.13 or higher.
If you want to develop it, you can use the `make`. It requires Go 1.15 or higher.

```
make
Expand Down
22 changes: 18 additions & 4 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/signal"
"runtime"
"runtime/debug"
"syscall"
"time"

Expand All @@ -31,12 +32,25 @@ type CLI struct {
outStream, errStream io.Writer
inputStream io.Reader

sClient slack.Slack
conf *config.Config
sClient slack.Slack
conf *config.Config
appVersion string
}

func NewCLI(outStream, errStream io.Writer, inputStream io.Reader) *CLI {
return &CLI{outStream: outStream, errStream: errStream, inputStream: inputStream}
return &CLI{appVersion: version(), outStream: outStream, errStream: errStream, inputStream: inputStream}
}

func version() string {
if Version != "" {
return Version
}

info, ok := debug.ReadBuildInfo()
if !ok {
return "(devel)"
}
return info.Main.Version
}

func (c *CLI) Run(args []string) int {
Expand Down Expand Up @@ -73,7 +87,7 @@ func (c *CLI) Run(args []string) int {
}

if version {
fmt.Fprintf(c.errStream, "notify_slack version %s; %s\n", Version, runtime.Version())
fmt.Fprintf(c.errStream, "notify_slack version %s; %s\n", c.appVersion, runtime.Version())
return ExitCodeOK
}

Expand Down

0 comments on commit 5755fb8

Please sign in to comment.