mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 14:17:56 +01:00
cmd/lncli: add version command that reads verrpc.GetVersion
This commit is contained in:
54
cmd/lncli/cmd_version.go
Normal file
54
cmd/lncli/cmd_version.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/lightningnetwork/lnd/build"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/lnclipb"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/verrpc"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var versionCommand = cli.Command{
|
||||
Name: "version",
|
||||
Usage: "Display lncli and lnd version info.",
|
||||
Description: `
|
||||
Returns version information about both lncli and lnd. If lncli is unable
|
||||
to connect to lnd, the command fails but still prints the lncli version.
|
||||
`,
|
||||
Action: actionDecorator(version),
|
||||
}
|
||||
|
||||
func version(ctx *cli.Context) error {
|
||||
conn := getClientConn(ctx, false)
|
||||
defer conn.Close()
|
||||
|
||||
versions := &lnclipb.VersionResponse{
|
||||
Lncli: &verrpc.Version{
|
||||
Commit: build.Commit,
|
||||
CommitHash: build.CommitHash,
|
||||
Version: build.Version(),
|
||||
AppMajor: uint32(build.AppMajor),
|
||||
AppMinor: uint32(build.AppMinor),
|
||||
AppPatch: uint32(build.AppPatch),
|
||||
AppPreRelease: build.AppPreRelease,
|
||||
BuildTags: build.Tags(),
|
||||
GoVersion: build.GoVersion,
|
||||
},
|
||||
}
|
||||
|
||||
client := verrpc.NewVersionerClient(conn)
|
||||
|
||||
ctxb := context.Background()
|
||||
lndVersion, err := client.GetVersion(ctxb, &verrpc.VersionRequest{})
|
||||
if err != nil {
|
||||
printRespJSON(versions)
|
||||
return fmt.Errorf("unable fetch version from lnd: %v", err)
|
||||
}
|
||||
versions.Lnd = lndVersion
|
||||
|
||||
printRespJSON(versions)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user