mirror of
https://github.com/kopia/kopia.git
synced 2026-01-28 16:23:04 -05:00
added buildinfo command
This commit is contained in:
7
Makefile
7
Makefile
@@ -1,7 +1,10 @@
|
||||
VERSION=0.1-pre
|
||||
VERSION_SUFFIX=
|
||||
|
||||
all: install test lint vet
|
||||
|
||||
install:
|
||||
go install github.com/kopia/kopia/cmd/kopia
|
||||
go install -ldflags "-X main.buildVersion=$(VERSION) -X main.buildTime=`date -u '+%s'` -X main.buildGitHash=`git describe --dirty`" github.com/kopia/kopia/cmd/kopia
|
||||
|
||||
build:
|
||||
go build github.com/kopia/kopia/...
|
||||
@@ -28,7 +31,7 @@ dev-deps:
|
||||
go get -u github.com/newhook/go-symbols
|
||||
go get -u github.com/sqs/goreturns
|
||||
|
||||
test:
|
||||
test: install
|
||||
go test -timeout 30s github.com/kopia/kopia/...
|
||||
|
||||
vtest:
|
||||
|
||||
37
cmd/kopia/command_buildinfo.go
Normal file
37
cmd/kopia/command_buildinfo.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
buildInfoCommand = app.Command("buildinfo", "Show build information").Hidden()
|
||||
|
||||
buildVersion = "UNKNOWN"
|
||||
buildGitHash = "UNKNOWN"
|
||||
buildTime = ""
|
||||
)
|
||||
|
||||
func buildTimeString() string {
|
||||
t, err := strconv.ParseInt(buildTime, 10, 64)
|
||||
if err == nil {
|
||||
return time.Unix(t, 0).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
return "UNKNOWN"
|
||||
}
|
||||
|
||||
func init() {
|
||||
buildInfoCommand.Action(runBuildInfoCommand)
|
||||
}
|
||||
|
||||
func runBuildInfoCommand(context *kingpin.ParseContext) error {
|
||||
fmt.Println("Version:", buildVersion)
|
||||
fmt.Println("Hash: ", buildGitHash)
|
||||
fmt.Println("Built: ", buildTimeString())
|
||||
return nil
|
||||
}
|
||||
@@ -17,11 +17,13 @@
|
||||
)
|
||||
|
||||
var (
|
||||
app = kingpin.New("kopia", "Kopia - Online Backup").Version("0.0.1").Author("http://kopia.github.io/")
|
||||
app = kingpin.New("kopia", "Kopia - Online Backup").Author("http://kopia.github.io/")
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
log.SetOutput(os.Stderr)
|
||||
app.Version(buildVersion)
|
||||
kingpin.MustParse(app.Parse(os.Args[1:]))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user