Skip to content

Commit

Permalink
🔨 make to show version info
Browse files Browse the repository at this point in the history
  • Loading branch information
Omochice committed Jul 22, 2021
1 parent 3fb5d7f commit b64562f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ builds:
binary: deepl-translate-cli
ldflags:
- -s -w
- -X main.Version={{.Version}}
- -X main.Revision={{.ShortCommit}}
- -X main.version={{.Version}}
- -X main.commit={{.ShortCommit}}
env:
- CGO_ENABLED=0
archives:
Expand Down
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,30 @@ import (
"os"
"path/filepath"
"runtime"
"runtime/debug"

"github.com/mattn/go-isatty"
"github.com/urfave/cli/v2"
)

var (
version = "develop"
version = ""
commit = "none"
date = "unkdown"
buildBy = "unkdown"
)

func getVersion() string {
if version != "" {
return version
}
i, ok := debug.ReadBuildInfo()
if !ok {
return "unknown"
}
return i.Main.Version
}

type Setting struct {
AuthKey string `json:"-"`
SourceLang string `json:"source_lang"`
Expand Down Expand Up @@ -144,7 +156,7 @@ func main() {
Name: "deepl-translate-cli",
Usage: "Translate sentences.",
UsageText: "deepl-translate-cli [-s|-t] <inputfile | --stdin> ",
Version: fmt.Sprintf("%s (rev %s) [%s %s %s] [build at %s by %s]", version, commit, runtime.GOOS, runtime.GOARCH, runtime.Version(), date, buildBy),
Version: fmt.Sprintf("%s (rev %s) [%s %s %s] [build at %s by %s]", getVersion(), commit, runtime.GOOS, runtime.GOARCH, runtime.Version(), date, buildBy),
Authors: []*cli.Author{
&cli.Author{
Name: "Omochice",
Expand Down

0 comments on commit b64562f

Please sign in to comment.