Skip to content

Commit

Permalink
feat: add new version command
Browse files Browse the repository at this point in the history
Signed-off-by: thomasgouveia <gouveia.thomas@outlook.fr>
  • Loading branch information
thomasgouveia committed May 14, 2023
1 parent 0e38a2c commit e8f6a37
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func Execute() {
}

func init() {
RootCmd.AddCommand(versionCmd)
RootCmd.AddCommand(config.RootCmd)
RootCmd.AddCommand(function.RootCmd)
RootCmd.AddCommand(runtime.RootCmd)
Expand Down
28 changes: 28 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -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
},
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit e8f6a37

Please sign in to comment.