Skip to content

Commit 92ebce3

Browse files
authored
feat(cmd): add server version to cli (chainloop-dev#1620)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 05b46ab commit 92ebce3

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

app/cli/cmd/version.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
package cmd
1717

1818
import (
19+
"context"
1920
"crypto/sha256"
2021
"fmt"
2122
"hash"
2223
"io"
2324
"os"
2425

26+
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
2527
"github.com/spf13/cobra"
2628
)
2729

@@ -38,8 +40,30 @@ func NewVersionCmd() *cobra.Command {
3840
return &cobra.Command{
3941
Use: "version",
4042
Short: "Command line version",
41-
Run: func(cmd *cobra.Command, args []string) {
42-
fmt.Printf("%s version %s\n", appName, Version)
43+
RunE: func(_ *cobra.Command, _ []string) error {
44+
var version = struct {
45+
Client string `json:"client"`
46+
Server string `json:"server"`
47+
}{
48+
Client: Version,
49+
Server: "unknown",
50+
}
51+
52+
if actionOpts.CPConnection != nil {
53+
res, err := pb.NewStatusServiceClient(actionOpts.CPConnection).Infoz(context.Background(), &pb.InfozRequest{})
54+
if err == nil {
55+
version.Server = res.Version
56+
}
57+
}
58+
59+
if flagOutputFormat == formatJSON {
60+
return encodeJSON(version)
61+
}
62+
63+
fmt.Printf("Client Version: %s\n", version.Client)
64+
fmt.Printf("Server Version: %s\n", version.Server)
65+
66+
return nil
4367
},
4468
}
4569
}

0 commit comments

Comments
 (0)