1
0
Fork 0

Merge pull request #807 from rqlite/cli-version

rqlite CLI provides version information
master
Philip O'Toole 3 years ago committed by GitHub
commit 9cc675b2f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,6 +12,7 @@ The data API and cluster-management API remain unchanged however, so client code
### New features ### New features
- [PR #796](https://github.com/rqlite/rqlite/pull/796): `nodes/` API reports real-time status of other nodes in cluster. Fixes [issue #768](https://github.com/rqlite/rqlite/issues/768). - [PR #796](https://github.com/rqlite/rqlite/pull/796): `nodes/` API reports real-time status of other nodes in cluster. Fixes [issue #768](https://github.com/rqlite/rqlite/issues/768).
- [PR #802](https://github.com/rqlite/rqlite/pull/802): Add `.sysdump` command to rqlite CLI. - [PR #802](https://github.com/rqlite/rqlite/pull/802): Add `.sysdump` command to rqlite CLI.
- [PR #807](https://github.com/rqlite/rqlite/pull/807): rqlite CLI displays build information. Fixes [issue #768](https://github.com/rqlite/rqlite/issues/806).
### Implementation changes and bug fixes ### Implementation changes and bug fixes
- [PR #792](https://github.com/rqlite/rqlite/pull/792): Fetch leader HTTP API addresses on demand. - [PR #792](https://github.com/rqlite/rqlite/pull/792): Fetch leader HTTP API addresses on demand.

@ -17,6 +17,7 @@ import (
"github.com/Bowery/prompt" "github.com/Bowery/prompt"
"github.com/mkideal/cli" "github.com/mkideal/cli"
"github.com/rqlite/rqlite/cmd"
) )
const maxRedirect = 21 const maxRedirect = 21
@ -30,6 +31,7 @@ type argT struct {
Insecure bool `cli:"i,insecure" usage:"do not verify rqlited HTTPS certificate" dft:"false"` Insecure bool `cli:"i,insecure" usage:"do not verify rqlited HTTPS certificate" dft:"false"`
CACert string `cli:"c,ca-cert" usage:"path to trusted X.509 root CA certificate"` CACert string `cli:"c,ca-cert" usage:"path to trusted X.509 root CA certificate"`
Credentials string `cli:"u,user" usage:"set basic auth credentials in form username:password"` Credentials string `cli:"u,user" usage:"set basic auth credentials in form username:password"`
Version bool `cli:"v,version" usage:"display CLI version"`
} }
var cliHelp = []string{ var cliHelp = []string{
@ -57,6 +59,12 @@ func main() {
return nil return nil
} }
if argv.Version {
ctx.String("Version %s, commmit %s, branch %s, built on %s\n", cmd.Version,
cmd.Commit, cmd.Branch, cmd.Buildtime)
return nil
}
client, err := getHTTPClient(argv) client, err := getHTTPClient(argv)
if err != nil { if err != nil {
ctx.String("%s %v\n", ctx.Color().Red("ERR!"), err) ctx.String("%s %v\n", ctx.Color().Red("ERR!"), err)
@ -70,7 +78,8 @@ func main() {
} }
fmt.Println("Welcome to the rqlite CLI. Enter \".help\" for usage hints.") fmt.Println("Welcome to the rqlite CLI. Enter \".help\" for usage hints.")
fmt.Printf("Connected to version %s\n", version) fmt.Printf("Version %s, commit %s, branch %s\n", cmd.Version, cmd.Commit, cmd.Branch)
fmt.Printf("Connected to rqlited version %s\n", version)
timer := false timer := false
prefix := fmt.Sprintf("%s:%d>", argv.Host, argv.Port) prefix := fmt.Sprintf("%s:%d>", argv.Host, argv.Port)

@ -19,6 +19,7 @@ import (
"github.com/rqlite/rqlite/auth" "github.com/rqlite/rqlite/auth"
"github.com/rqlite/rqlite/cluster" "github.com/rqlite/rqlite/cluster"
"github.com/rqlite/rqlite/cmd"
"github.com/rqlite/rqlite/disco" "github.com/rqlite/rqlite/disco"
httpd "github.com/rqlite/rqlite/http" httpd "github.com/rqlite/rqlite/http"
"github.com/rqlite/rqlite/store" "github.com/rqlite/rqlite/store"
@ -36,15 +37,6 @@ const logo = `
|_| |_|
` `
// These variables are populated via the Go linker.
var (
version = "6"
commit = "unknown"
branch = "unknown"
buildtime = "unknown"
features = []string{}
)
var httpAddr string var httpAddr string
var httpAdv string var httpAdv string
var joinSrcIP string var joinSrcIP string
@ -148,7 +140,7 @@ func main() {
if showVersion { if showVersion {
fmt.Printf("%s %s %s %s %s (commit %s, branch %s)\n", fmt.Printf("%s %s %s %s %s (commit %s, branch %s)\n",
name, version, runtime.GOOS, runtime.GOARCH, runtime.Version(), commit, branch) name, cmd.Version, runtime.GOOS, runtime.GOARCH, runtime.Version(), cmd.Commit, cmd.Branch)
os.Exit(0) os.Exit(0)
} }
@ -173,7 +165,7 @@ func main() {
log.SetFlags(log.LstdFlags) log.SetFlags(log.LstdFlags)
log.SetOutput(os.Stderr) log.SetOutput(os.Stderr)
log.SetPrefix(fmt.Sprintf("[%s] ", name)) log.SetPrefix(fmt.Sprintf("[%s] ", name))
log.Printf("%s starting, version %s, commit %s, branch %s", name, version, commit, branch) log.Printf("%s starting, version %s, commit %s, branch %s", name, cmd.Version, cmd.Commit, cmd.Branch)
log.Printf("%s, target architecture is %s, operating system target is %s", runtime.Version(), runtime.GOARCH, runtime.GOOS) log.Printf("%s, target architecture is %s, operating system target is %s", runtime.Version(), runtime.GOARCH, runtime.GOOS)
log.Printf("launch command: %s", strings.Join(os.Args, " ")) log.Printf("launch command: %s", strings.Join(os.Args, " "))
@ -404,10 +396,10 @@ func startHTTPService(str *store.Store, cltr *cluster.Service) error {
s.Expvar = expvar s.Expvar = expvar
s.Pprof = pprofEnabled s.Pprof = pprofEnabled
s.BuildInfo = map[string]interface{}{ s.BuildInfo = map[string]interface{}{
"commit": commit, "commit": cmd.Commit,
"branch": branch, "branch": cmd.Branch,
"version": version, "version": cmd.Version,
"build_time": buildtime, "build_time": cmd.Buildtime,
} }
return s.Start() return s.Start()
} }

@ -0,0 +1,16 @@
package cmd
// These variables are populated via the Go linker.
var (
// rqlite version
Version = "6"
// Commit this code was built at.
Commit = "unknown"
// Branch the code was built from.
Branch = "unknown"
// Timestamp of build.
Buildtime = "unknown"
)

@ -37,7 +37,9 @@ cd $tmp_build/src/github.com/rqlite
git clone $REPO_URL git clone $REPO_URL
cd rqlite cd rqlite
go get -d ./... go get -d ./...
go install -ldflags="-X main.version=$VERSION -X main.branch=$branch -X main.commit=$commit -X main.buildtime=$buildtime" ./...
LINKER_PKG_PATH=github.com/rqlite/rqlite/cmd
go install -ldflags="-X $LINKER_PKG_PATH.Version=$VERSION -X $LINKER_PKG_PATH.Branch=$branch -X $LINKER_PKG_PATH.Commit=$commit -X $LINKER_PKG_PATH.Buildtime=$buildtime" ./...
release=`echo rqlite-$VERSION-$kernel-$machine | tr '[:upper:]' '[:lower:]'` release=`echo rqlite-$VERSION-$kernel-$machine | tr '[:upper:]' '[:lower:]'`
release_pkg=${release}.tar.gz release_pkg=${release}.tar.gz

Loading…
Cancel
Save