From e8f6a371ee00179de835862fd08e13ddee281e13 Mon Sep 17 00:00:00 2001 From: thomasgouveia Date: Sat, 13 May 2023 23:31:24 +0200 Subject: [PATCH] feat: add new version command Signed-off-by: thomasgouveia --- cmd/root.go | 1 + cmd/version.go | 28 ++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 cmd/version.go diff --git a/cmd/root.go b/cmd/root.go index 6d2f043..eda9ee2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -90,6 +90,7 @@ func Execute() { } func init() { + RootCmd.AddCommand(versionCmd) RootCmd.AddCommand(config.RootCmd) RootCmd.AddCommand(function.RootCmd) RootCmd.AddCommand(runtime.RootCmd) diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..3651457 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "fmt" + + "github.com/morty-faas/cli/build" + "github.com/morty-faas/cli/cliconfig" + morty "github.com/morty-faas/morty/pkg/client/controller" + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Get the current version of the CLI and of the Morty server of the current context.", + Long: "Get the current version of the CLI and of the Morty server of the current context.", + RunE: func(cmd *cobra.Command, args []string) error { + client := cmd.Context().Value(cliconfig.ControllerClientContextKey{}).(*morty.APIClient) + + metadata, _, err := client.ConfigurationApi.GetServerMetadata(cmd.Context()).Execute() + if err != nil { + return err + } + + fmt.Printf("CLI : '%s' (commit: %s)\n", build.Version, build.GitCommit) + fmt.Printf("Server : '%s' (commit: %s)\n", metadata.GetVersion(), metadata.GetGitCommit()) + return nil + }, +} diff --git a/go.mod b/go.mod index cca0e0e..6060b72 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ retract ( require ( github.com/briandowns/spinner v1.23.0 github.com/hashicorp/go-getter v1.7.1 - github.com/morty-faas/morty v1.1.0-RC1 + github.com/morty-faas/morty v1.1.0-RC1.0.20230513211117-5beade79921b github.com/olekukonko/tablewriter v0.0.5 github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 github.com/sirupsen/logrus v1.9.0 diff --git a/go.sum b/go.sum index b143680..fca76d5 100644 --- a/go.sum +++ b/go.sum @@ -396,6 +396,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/morty-faas/morty v1.1.0-RC1 h1:Viy5y8Ghnwuf/3P0wHHjIIahNopDDQUqFFYljojoTBI= github.com/morty-faas/morty v1.1.0-RC1/go.mod h1:HRJ867IsYSF0dROI5eAmQjHkSI7+Trs6VSXHSV0EMtw= +github.com/morty-faas/morty v1.1.0-RC1.0.20230513211117-5beade79921b h1:WxBl1O/VurXy3AMeZrkdLtJAtbDyvrThO02GGVRtLg0= +github.com/morty-faas/morty v1.1.0-RC1.0.20230513211117-5beade79921b/go.mod h1:knCFikLpKsyLm9qjXseYV3ZtHQtfXuTNSOm7thTeejk= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 h1:Yl0tPBa8QPjGmesFh1D0rDy+q1Twx6FyU7VWHi8wZbI=