github.com/klaytn/klaytn@v1.10.2/cmd/utils/nodecmd/versioncmd.go (about)

     1  // Modifications Copyright 2018 The klaytn Authors
     2  // Copyright 2016 The go-ethereum Authors
     3  // This file is part of go-ethereum.
     4  //
     5  // go-ethereum is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // go-ethereum is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  // GNU General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU General Public License
    16  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  // This file is derived from cmd/geth/misccmd.go (2018/06/04).
    19  // Modified and improved for the klaytn development.
    20  
    21  package nodecmd
    22  
    23  import (
    24  	"fmt"
    25  
    26  	"github.com/klaytn/klaytn/cmd/utils"
    27  	"github.com/klaytn/klaytn/params"
    28  	"gopkg.in/urfave/cli.v1"
    29  )
    30  
    31  var (
    32  	// Git SHA1 commit hash of the release (set via linker flags)
    33  	gitCommit = ""
    34  
    35  	// Git tag (set via linker flags if exists)
    36  	gitTag = ""
    37  )
    38  
    39  var VersionCommand = cli.Command{
    40  	Action:    utils.MigrateFlags(version),
    41  	Name:      "version",
    42  	Usage:     "Show version number",
    43  	ArgsUsage: " ",
    44  	Category:  "MISCELLANEOUS COMMANDS",
    45  }
    46  
    47  func version(ctx *cli.Context) error {
    48  	fmt.Print("Klaytn ")
    49  	if gitTag != "" {
    50  		// stable version
    51  		fmt.Println(params.Version)
    52  	} else {
    53  		// unstable version
    54  		fmt.Println(params.VersionWithCommit(gitCommit))
    55  	}
    56  	return nil
    57  }
    58  
    59  // GetGitCommit returns gitCommit set by linker flags.
    60  func GetGitCommit() string {
    61  	return gitCommit
    62  }