mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
c1058fac70
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6746 GitOrigin-RevId: d8271cdb890eecc861c33d765b3a364e904bee38
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package commands
|
|
|
|
import (
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/errors"
|
|
"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 {
|
|
op := genOpName(cmd, "PreRunE")
|
|
ec.Viper = viper.New()
|
|
if err := ec.Prepare(); err != nil {
|
|
return errors.E(op, err)
|
|
}
|
|
return nil
|
|
},
|
|
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
|
|
}
|