Permalink
Browse files

update NewVersionCommand

Signed-off-by: Peter Edge <peter.edge@gmail.com>
  • Loading branch information...
peter-edge committed Sep 20, 2016
1 parent 560713b commit bd3beee6a03cd820a902905a96aca53c5395be6b
Showing with 10 additions and 14 deletions.
  1. +10 −14 client/protoclient.go
@@ -2,34 +2,30 @@ package protoclient // import "go.pedge.io/proto/client"

import (
"fmt"
"os"

"go.pedge.io/pkg/cobra"
"go.pedge.io/proto/version"

"github.com/spf13/cobra"
"google.golang.org/grpc"
)

// NewVersionCommand creates a new command to print the version of the client and server.
func NewVersionCommand(
clientConn *grpc.ClientConn,
clientVersion *protoversion.Version,
errorHandler func(error),
) *cobra.Command {
func NewVersionCommand(clientVersion *protoversion.Version, clientConnFunc func() (*grpc.ClientConn, error)) *cobra.Command {
return &cobra.Command{
Use: "version",
Long: "Print the version.",
Run: func(cmd *cobra.Command, args []string) {
Run: pkgcobra.RunFixedArgs(0, func(args []string) error {
clientConn, err := clientConnFunc()
if err != nil {
return err
}
serverVersion, err := protoversion.GetServerVersion(clientConn)
if err != nil {
if errorHandler != nil {
errorHandler(err)
return
}
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
return err
}
fmt.Printf("Client: %s\nServer: %s\n", clientVersion.VersionString(), serverVersion.VersionString())
},
return nil
}),
}
}

0 comments on commit bd3beee

Please sign in to comment.