2018-06-28 08:40:18 +03:00
package commands
import (
2021-06-16 14:44:15 +03:00
"github.com/hasura/graphql-engine/cli/v2"
2022-11-07 14:13:12 +03:00
"github.com/hasura/graphql-engine/cli/v2/internal/errors"
2021-06-16 14:44:15 +03:00
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
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" ,
2022-12-30 06:50:48 +03:00
Long : "If unsure which version of the CLI you are using, you can use this command to print the version of the CLI. This command can also be used to check if a new version of the CLI is available." ,
2018-06-28 08:40:18 +03:00
SilenceUsage : true ,
PreRunE : func ( cmd * cobra . Command , args [ ] string ) error {
2022-11-07 14:13:12 +03:00
op := genOpName ( cmd , "PreRunE" )
2019-01-28 16:55:28 +03:00
ec . Viper = viper . New ( )
2022-11-07 14:13:12 +03:00
if err := ec . Prepare ( ) ; err != nil {
return errors . E ( op , err )
}
return nil
2018-06-28 08:40:18 +03:00
} ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2021-06-16 14:44:15 +03:00
logger := logrus . New ( )
2021-07-16 08:26:00 +03:00
logger . SetOutput ( ec . Stdout )
2021-06-16 14:44:15 +03:00
logger . SetFormatter ( & logrus . TextFormatter { DisableTimestamp : true , DisableColors : ec . NoColor } )
if ! ec . IsTerminal {
logger . SetFormatter ( & logrus . JSONFormatter { PrettyPrint : false } )
2021-05-31 07:12:31 +03:00
}
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
}