Skip to content

Commit

Permalink
Add message that the server does not support commands
Browse files Browse the repository at this point in the history
  • Loading branch information
hyun98 committed Jul 28, 2024
1 parent e2a6d54 commit 742d6d1
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions cmd/yorkie/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"runtime"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -40,8 +41,9 @@ var (

func newVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print the version number of Yorkie",
Use: "version",
Short: "Print the version number of Yorkie",
PreRunE: config.Preload,
RunE: func(cmd *cobra.Command, args []string) error {
if err := Validate(); err != nil {
return err
Expand Down Expand Up @@ -93,15 +95,13 @@ func newVersionCmd() *cobra.Command {

switch output {
case "":
fmt.Printf("Yorkie Client: %s\n", versionInfo.ClientVersion.YorkieVersion)
fmt.Printf("Go: %s\n", versionInfo.ClientVersion.GoVersion)
fmt.Printf("Build Date: %s\n", versionInfo.ClientVersion.BuildDate)
cmd.Printf("Yorkie Client: %s\n", versionInfo.ClientVersion.YorkieVersion)
cmd.Printf("Go: %s\n", versionInfo.ClientVersion.GoVersion)
cmd.Printf("Build Date: %s\n", versionInfo.ClientVersion.BuildDate)
if versionInfo.ServerVersion != nil {
fmt.Printf("Yorkie Server: %s\n", versionInfo.ServerVersion.YorkieVersion)
fmt.Printf("Go: %s\n", versionInfo.ServerVersion.GoVersion)
fmt.Printf("Build Date: %s\n", versionInfo.ServerVersion.BuildDate)
} else if serverErr != nil {
fmt.Printf("Error fetching server version: %v\n", serverErr)
cmd.Printf("Yorkie Server: %s\n", versionInfo.ServerVersion.YorkieVersion)
cmd.Printf("Go: %s\n", versionInfo.ServerVersion.GoVersion)
cmd.Printf("Build Date: %s\n", versionInfo.ServerVersion.BuildDate)
}
case "yaml":
marshalled, err := yaml.Marshal(&versionInfo)
Expand All @@ -117,6 +117,15 @@ func newVersionCmd() *cobra.Command {
fmt.Println(string(marshalled))
}

if serverErr != nil {
cmd.Printf("Error fetching server version: ")
if strings.Contains(serverErr.Error(), "unimplemented") {
cmd.Printf("The server does not support this operation. You might need to check your server version.\n")
} else {
cmd.Print(serverErr)
}
}

return nil
},
}
Expand Down

0 comments on commit 742d6d1

Please sign in to comment.