mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 01:44:03 +03:00
4ed8ba8bb3
closes https://github.com/hasura/graphql-engine/issues/7202 https://github.com/hasura/graphql-engine-mono/pull/1781 Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: bcbdf74773aa8f653ebe62c5bf00bcbda1aa51ee
41 lines
1.1 KiB
Go
41 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"
|
|
)
|
|
|
|
// 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(ec.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
|
|
}
|