curver
is an easy way to display the version of a CUI tool made with go.
You can display the version either with go install
or with built binaries.
curver
is named as an abbreviation of current version
.
go get github.com/harakeishi/curver
import (
"github.com/harakeishi/curver"
)
Visit the docs on GoDoc
If the value using ldflag is stored in the variable Version, that value will be displayed. Otherwise, it will display the build information embedded in the running binary.
package main
import (
"github.com/harakeishi/curver"
)
func main () {
curver.EchoVersion()
}
$ go build -ldflags '-X github.com/harakeishi/curver.Version=v0.1.0' -o ./main
This will display the following format.
$ ./main
version: v0.1.0
If you want to embed the result of 'git tag', you can do the following
$ go build -ldflags "-X github.com/harakeishi/curver.Version=$(git describe --tags)" -o ./main
If you are using goreleaser to do the release, do the following
builds:
- ldflags:
- -s -w -X github.com/harakeishi/curver.Version={{.Version}}
The following will return the version as a string.
package main
import (
"github.com/harakeishi/curver"
)
func main () {
version := curver.GetVersion()
}
Copyright (c) 2022 harakeishi Licensed under MIT
Thanks goes to these wonderful people (emoji key):
原 慧士 💻 |
Akimo 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!