graphql-engine/cli/commands/version.go
Aravind K P 3136ffad1b cli: update go.mod
>

### Description
Update `go.mod` to allow other packages to import [v2.0.0 versions](https://blog.golang.org/v2-go-modules).

### Changelog

- [x] `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label.

### Affected components

- [x] CLI

https://github.com/hasura/graphql-engine-mono/pull/1584

GitOrigin-RevId: a5d17ad20289d1cd7217763f56ef3ba6552d69c4
2021-06-16 11:45:07 +00:00

42 lines
1.1 KiB
Go

package commands
import (
"github.com/hasura/graphql-engine/cli/v2"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
)
// NewVersionCmd returns the version command
func NewVersionCmd(ec *cli.ExecutionContext) *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Print the CLI version",
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
ec.Viper = viper.New()
return ec.Prepare()
},
RunE: func(cmd *cobra.Command, args []string) error {
logger := logrus.New()
logger.SetOutput(os.Stdout)
logger.SetFormatter(&logrus.TextFormatter{DisableTimestamp: true, DisableColors: ec.NoColor})
if !ec.IsTerminal {
logger.SetFormatter(&logrus.JSONFormatter{PrettyPrint: false})
}
logger.WithField("version", ec.Version.GetCLIVersion()).Info("hasura cli")
err := ec.Validate()
if err == nil {
logger.
WithField("endpoint", ec.Config.ServerConfig.Endpoint).
WithField("version", ec.Version.GetServerVersion()).
Info("hasura graphql engine")
}
return nil
},
}
return versionCmd
}