github.com/decred/dcrlnd@v0.7.6/cmd/dcrlncli/cmd_version.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  
     7  	"github.com/decred/dcrlnd/build"
     8  	"github.com/decred/dcrlnd/lnrpc/lnclipb"
     9  	"github.com/decred/dcrlnd/lnrpc/verrpc"
    10  	"github.com/urfave/cli"
    11  )
    12  
    13  var versionCommand = cli.Command{
    14  	Name:  "version",
    15  	Usage: "Display lncli and lnd version info.",
    16  	Description: `
    17  	Returns version information about both lncli and lnd. If lncli is unable
    18  	to connect to lnd, the command fails but still prints the lncli version.
    19  	`,
    20  	Action: actionDecorator(version),
    21  }
    22  
    23  func version(ctx *cli.Context) error {
    24  	ctxc := getContext()
    25  	conn := getClientConn(ctx, false)
    26  	defer conn.Close()
    27  
    28  	major, minor, patch := build.MajorMinorPatch()
    29  
    30  	versions := &lnclipb.VersionResponse{
    31  		Lncli: &verrpc.Version{
    32  			Commit:        build.Commit,
    33  			CommitHash:    build.Commit,
    34  			Version:       build.Version(),
    35  			AppMajor:      uint32(major),
    36  			AppMinor:      uint32(minor),
    37  			AppPatch:      uint32(patch),
    38  			AppPreRelease: build.PreRelease,
    39  			BuildTags:     nil,
    40  			GoVersion:     runtime.Version(),
    41  		},
    42  	}
    43  
    44  	client := verrpc.NewVersionerClient(conn)
    45  
    46  	lndVersion, err := client.GetVersion(ctxc, &verrpc.VersionRequest{})
    47  	if err != nil {
    48  		printRespJSON(versions)
    49  		return fmt.Errorf("unable fetch version from lnd: %v", err)
    50  	}
    51  	versions.Lnd = lndVersion
    52  
    53  	printRespJSON(versions)
    54  
    55  	return nil
    56  }