This commit is contained in:
Pavel Vorobyov
2019-10-08 13:38:55 +03:00
parent 83e0329210
commit f13072cc03
4 changed files with 39 additions and 1 deletions

View File

@@ -8,6 +8,6 @@ jobs:
- checkout
- run:
name: Building XC
command: go build -o xc cmd/xc/main.go
command: ./build.sh
- store_artifacts:
path: /tmp/build/xc

14
build.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
kname=`uname -s`
kver=`uname -r`
karch=`uname -m`
gitcommit=`git rev-list --tags --max-count=1`
appver=`git describe --tags $gitcommit`
appbuild=`git rev-list ${appver}.. --count`
importroot="github.com/viert/xc/cli"
go build -o xc \
-ldflags="-X $importroot.appVersion=$appver -X $importroot.appBuild=$appbuild -X $importroot.kernelName=$kname -X $importroot.kernelVersion=$kver -X $importroot.kernelArch=$karch" \
cmd/xc/main.go

View File

@@ -50,6 +50,7 @@ func (c *Cli) setupCmdHandlers() {
c.handlers["use_password_manager"] = c.doUsePasswordManager
c.handlers["distribute_type"] = c.doDistributeType
c.handlers["_passmgr_debug"] = c.doPassmgrDebug
c.handlers["version"] = c.doVersion
commands := make([]string, len(c.handlers))
i := 0
@@ -60,6 +61,10 @@ func (c *Cli) setupCmdHandlers() {
c.completer = newCompleter(c.store, commands)
}
func (c *Cli) doVersion(name string, argsLine string, args ...string) {
term.Successf("XC version %s\n", version())
}
func (c *Cli) doExit(name string, argsLine string, args ...string) {
c.stopped = true
}

19
cli/version.go Normal file
View File

@@ -0,0 +1,19 @@
package cli
import "fmt"
var (
appVersion = ""
appBuild = ""
kernelName = ""
kernelVersion = ""
kernelArch = ""
)
func version() string {
if appVersion == "" {
return "dev"
}
return fmt.Sprintf("%s-%s (%s %s %s)", appVersion, appBuild, kernelName, kernelVersion, kernelArch)
}