Skip to content

Commit

Permalink
server/cmd: add flag to print version information (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
Librazy authored and overvenus committed Oct 30, 2016
1 parent d41f2f6 commit 6b92a76
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
8 changes: 7 additions & 1 deletion cmd/pd-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ import (
func main() {
cfg := server.NewConfig()
err := cfg.Parse(os.Args[1:])

if cfg.Version {
server.PrintPDInfo()
os.Exit(0)
}

switch errors.Cause(err) {
case nil:
case flag.ErrHelp:
Expand All @@ -42,7 +48,7 @@ func main() {
log.Fatalf("initalize logger err %s\n", err)
}

server.PrintPDInfo()
server.LogPDInfo()

server.PushMetric(cfg)

Expand Down
3 changes: 3 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
type Config struct {
*flag.FlagSet `json:"-"`

Version bool

ClientUrls string `toml:"client-urls" json:"client-urls"`
PeerUrls string `toml:"peer-urls" json:"peer-urls"`
AdvertiseClientUrls string `toml:"advertise-client-urls" json:"advertise-client-urls"`
Expand Down Expand Up @@ -84,6 +86,7 @@ func NewConfig() *Config {
cfg.FlagSet = flag.NewFlagSet("pd", flag.ContinueOnError)
fs := cfg.FlagSet

fs.BoolVar(&cfg.Version, "v", false, "print version information and exit")
fs.StringVar(&cfg.configFile, "config", "", "Config file")

fs.Uint64Var(&cfg.ClusterID, "cluster-id", 0, "initial cluster ID for the pd cluster")
Expand Down
10 changes: 8 additions & 2 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@ var (
PDGitHash = "None"
)

// PrintPDInfo prints the PD version information.
func PrintPDInfo() {
// LogPDInfo prints the PD version information.
func LogPDInfo() {
log.Infof("Welcome to Placement Driver (PD).")
log.Infof("Version:")
log.Infof("Git Commit Hash: %s", PDGitHash)
log.Infof("UTC Build Time: %s", PDBuildTS)
}

// PrintPDInfo prints the PD version information without log info.
func PrintPDInfo() {
fmt.Println("Git Commit Hash:", PDGitHash)
fmt.Println("UTC Build Time: ", PDBuildTS)
}

const zeroDuration = time.Duration(0)

// PushMetric pushs metircs in background.
Expand Down

0 comments on commit 6b92a76

Please sign in to comment.