mirror of
https://github.com/grdl/git-get.git
synced 2026-02-09 12:39:18 +00:00
Move the version metadata to cfg packageThis way it can be used by multiple binaries.
This commit is contained in:
@@ -3,20 +3,29 @@ before:
|
|||||||
- go mod download
|
- go mod download
|
||||||
|
|
||||||
builds:
|
builds:
|
||||||
- main: ./cmd/main.go
|
- id: git-list
|
||||||
binary: "git-get"
|
main: ./cmd/list/main.go
|
||||||
|
binary: git-list
|
||||||
|
ldflags:
|
||||||
|
- -s -w
|
||||||
|
- -X git-get/pkg/cfg.version={{.Version}}
|
||||||
|
- -X git-get/pkg/cfg.commit={{.Commit}}
|
||||||
|
- -X git-get/pkg/cfg.date={{.Date}}
|
||||||
goos:
|
goos:
|
||||||
- linux
|
- linux
|
||||||
- darwin
|
- darwin
|
||||||
- windows
|
- windows
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- replacements:
|
- id: archive
|
||||||
darwin: macOS
|
builds:
|
||||||
linux: Linux
|
- git-list
|
||||||
windows: Windows
|
replacements:
|
||||||
386: i386
|
darwin: macOS
|
||||||
amd64: x86_64
|
linux: Linux
|
||||||
|
windows: Windows
|
||||||
|
386: i386
|
||||||
|
amd64: x86_64
|
||||||
|
|
||||||
checksum:
|
checksum:
|
||||||
name_template: 'checksums.txt'
|
name_template: 'checksums.txt'
|
||||||
|
|||||||
@@ -13,18 +13,12 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
version = "dev"
|
|
||||||
commit = "unknown"
|
|
||||||
date = "unknown"
|
|
||||||
)
|
|
||||||
|
|
||||||
var cmd = &cobra.Command{
|
var cmd = &cobra.Command{
|
||||||
Use: "git-get <repo>",
|
Use: "git-get <repo>",
|
||||||
Short: "git get",
|
Short: "git get",
|
||||||
Run: Run,
|
Run: Run,
|
||||||
Args: cobra.MaximumNArgs(1), // TODO: add custom validator
|
Args: cobra.MaximumNArgs(1), // TODO: add custom validator
|
||||||
Version: fmt.Sprintf("%s - %s, build at %s", version, commit, date),
|
Version: cfg.Version(),
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -37,6 +38,23 @@ const (
|
|||||||
OutSimple = "simple"
|
OutSimple = "simple"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Version metadata set by ldflags during the build.
|
||||||
|
var (
|
||||||
|
version string
|
||||||
|
commit string
|
||||||
|
date string
|
||||||
|
)
|
||||||
|
|
||||||
|
// Version returns a string with version metadata: version number, git sha and build date.
|
||||||
|
// It returns "development" if version variables are not set during the build.
|
||||||
|
func Version() string {
|
||||||
|
if version == "" {
|
||||||
|
return "development"
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s - revision %s built at %s", version, commit[:6], date)
|
||||||
|
}
|
||||||
|
|
||||||
// gitconfig provides methods for looking up configiration values inside .gitconfig file
|
// gitconfig provides methods for looking up configiration values inside .gitconfig file
|
||||||
type gitconfig struct {
|
type gitconfig struct {
|
||||||
*config.Config
|
*config.Config
|
||||||
|
|||||||
Reference in New Issue
Block a user