mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-21 16:03:32 +01:00
version subcommand: unified client & server
This commit is contained in:
parent
7836ea36fc
commit
bf5099baac
57
client/version.go
Normal file
57
client/version.go
Normal file
@ -0,0 +1,57 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/zrepl/zrepl/config"
|
||||
"github.com/zrepl/zrepl/daemon"
|
||||
"github.com/zrepl/zrepl/version"
|
||||
"os"
|
||||
)
|
||||
|
||||
type VersionArgs struct {
|
||||
Show string
|
||||
Config *config.Config
|
||||
}
|
||||
|
||||
func RunVersion(args VersionArgs) {
|
||||
|
||||
die := func() {
|
||||
fmt.Fprintf(os.Stderr, "exiting after error\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if args.Show != "daemon" && args.Show != "client" && args.Show != "" {
|
||||
fmt.Fprintf(os.Stderr, "show flag must be 'client' or 'server' or be left empty")
|
||||
die()
|
||||
}
|
||||
|
||||
var clientVersion, daemonVersion *version.ZreplVersionInformation
|
||||
if args.Show == "client" || args.Show == "" {
|
||||
clientVersion = version.NewZreplVersionInformation()
|
||||
fmt.Printf("client: %s\n", clientVersion.String())
|
||||
}
|
||||
if args.Show == "daemon" || args.Show == "" {
|
||||
|
||||
httpc, err := controlHttpClient(args.Config.Global.Control.SockPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "server: error: %s\n", err)
|
||||
die()
|
||||
}
|
||||
|
||||
var info version.ZreplVersionInformation
|
||||
err = jsonRequestResponse(httpc, daemon.ControlJobEndpointVersion, "", &info)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "server: error: %s\n", err)
|
||||
die()
|
||||
}
|
||||
daemonVersion = &info
|
||||
fmt.Printf("server: %s\n", daemonVersion.String())
|
||||
}
|
||||
|
||||
if args.Show == "" {
|
||||
if clientVersion.Version != daemonVersion.Version {
|
||||
fmt.Fprintf(os.Stderr, "WARNING: client version != daemon version, restart zrepl daemon\n")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
15
main.go
15
main.go
@ -100,6 +100,19 @@ var configcheckCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var versionCmdArgs client.VersionArgs
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "print version of zrepl binary (for running daemon 'zrepl control version' command)",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
conf, err := config.ParseConfig(rootArgs.configFile)
|
||||
if err == nil {
|
||||
versionCmdArgs.Config = conf
|
||||
}
|
||||
client.RunVersion(versionCmdArgs)
|
||||
},
|
||||
}
|
||||
|
||||
var rootArgs struct {
|
||||
configFile string
|
||||
}
|
||||
@ -113,6 +126,8 @@ func init() {
|
||||
rootCmd.AddCommand(stdinserverCmd)
|
||||
rootCmd.AddCommand(bashcompCmd)
|
||||
rootCmd.AddCommand(configcheckCmd)
|
||||
versionCmd.Flags().StringVar(&versionCmdArgs.Show, "show", "", "version info to show (client|daemon)")
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
Loading…
Reference in New Issue
Block a user