github.com/klaytn/klaytn@v1.12.1/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/params"
    27  	"github.com/urfave/cli/v2"
    28  )
    29  
    30  var (
    31  	// Git SHA1 commit hash of the release (set via linker flags)
    32  	gitCommit = ""
    33  
    34  	// Git tag (set via linker flags if exists)
    35  	gitTag = ""
    36  )
    37  
    38  var VersionCommand = &cli.Command{
    39  	Action:    version,
    40  	Name:      "version",
    41  	Usage:     "Show version number",
    42  	ArgsUsage: " ",
    43  	Category:  "MISCELLANEOUS COMMANDS",
    44  }
    45  
    46  func version(ctx *cli.Context) error {
    47  	fmt.Print("Klaytn ")
    48  	if gitTag != "" {
    49  		// stable version
    50  		fmt.Println(params.Version)
    51  	} else {
    52  		// unstable version
    53  		fmt.Println(params.VersionWithCommit(gitCommit))
    54  	}
    55  	return nil
    56  }
    57  
    58  // GetGitCommit returns gitCommit set by linker flags.
    59  func GetGitCommit() string {
    60  	return gitCommit
    61  }