Skip to content

Commit

Permalink
fix ShowVersion (V/version) flag
Browse files Browse the repository at this point in the history
add copyright notices
  • Loading branch information
chappjc committed Mar 18, 2018
1 parent 6af5d9b commit 8b4547e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cmd/rebuilddb2/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// Copyright (c) 2018, The Decred developers
// Copyright (c) 2017, The dcrdata developers
// See LICENSE for details.

package main

import (
"fmt"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"

flags "github.com/btcsuite/go-flags"
Expand Down Expand Up @@ -135,12 +140,13 @@ func loadConfig() (*config, error) {
}

// Show the version and exit if the version flag was specified.
// appName := filepath.Base(os.Args[0])
// appName = strings.TrimSuffix(appName, filepath.Ext(appName))
// if preCfg.ShowVersion {
// fmt.Println(appName, "version", ver.String())
// os.Exit(0)
// }
appName := filepath.Base(os.Args[0])
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
if preCfg.ShowVersion {
fmt.Printf("%s version %s (Go version %s, %s-%s)\n", appName,
ver.String(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
os.Exit(0)
}

// Load additional config from file.
var configFileError error
Expand Down
4 changes: 4 additions & 0 deletions cmd/rebuilddb2/rebuilddb2.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2018, The Decred developers
// Copyright (c) 2017, The dcrdata developers
// See LICENSE for details.

package main

import (
Expand Down
38 changes: 38 additions & 0 deletions cmd/rebuilddb2/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2018, The Decred developers
// Copyright (c) 2017, The dcrdata developers
// See LICENSE for details.

package main

import "fmt"

type version struct {
Major, Minor, Patch int
Label string
Nick string
}

var ver = version{
Major: 2,
Minor: 0,
Patch: 0,
Label: ""}

// CommitHash may be set on the build command line:
// go build -ldflags "-X main.CommitHash=`git rev-parse --short HEAD`"
var CommitHash string

const appName string = "rebuilddb2"

func (v *version) String() string {
var hashStr string
if CommitHash != "" {
hashStr = "+" + CommitHash
}
if v.Label != "" {
return fmt.Sprintf("%d.%d.%d-%s%s",
v.Major, v.Minor, v.Patch, v.Label, hashStr)
}
return fmt.Sprintf("%d.%d.%d%s",
v.Major, v.Minor, v.Patch, hashStr)
}

0 comments on commit 8b4547e

Please sign in to comment.