2018-06-28 08:40:18 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2021-05-31 07:12:31 +03:00
|
|
|
"github.com/hasura/graphql-engine/cli"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"os"
|
2018-06-28 08:40:18 +03:00
|
|
|
)
|
|
|
|
|
2018-07-04 15:43:52 +03:00
|
|
|
// NewVersionCmd returns the version command
|
2018-06-28 08:40:18 +03:00
|
|
|
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 {
|
2019-01-28 16:55:28 +03:00
|
|
|
ec.Viper = viper.New()
|
2018-06-28 08:40:18 +03:00
|
|
|
return ec.Prepare()
|
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
2021-05-31 07:12:31 +03:00
|
|
|
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")
|
2018-07-04 15:43:52 +03:00
|
|
|
err := ec.Validate()
|
|
|
|
if err == nil {
|
2021-05-31 07:12:31 +03:00
|
|
|
logger.
|
2020-02-24 19:14:46 +03:00
|
|
|
WithField("endpoint", ec.Config.ServerConfig.Endpoint).
|
2018-07-04 15:43:52 +03:00
|
|
|
WithField("version", ec.Version.GetServerVersion()).
|
|
|
|
Info("hasura graphql engine")
|
|
|
|
}
|
2018-06-28 08:40:18 +03:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return versionCmd
|
|
|
|
}
|