mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
a398d3b190
GITHUB_PR_NUMBER: 6111 GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/6111 Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: 1f6517acfacb58c566bb5e48f74ea0dfa5c6f063
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
package commands
|
|
|
|
import (
|
|
"github.com/hasura/graphql-engine/cli"
|
|
"github.com/hasura/graphql-engine/cli/util"
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// NewSeedCmd will return the seed command
|
|
func NewSeedCmd(ec *cli.ExecutionContext) *cobra.Command {
|
|
v := viper.New()
|
|
ec.Viper = v
|
|
seedCmd := &cobra.Command{
|
|
Use: "seed",
|
|
Aliases: []string{"sd", "seeds"},
|
|
Short: "Manage seed data",
|
|
SilenceUsage: true,
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
err := ec.Prepare()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := ec.Validate(); err != nil {
|
|
return err
|
|
}
|
|
if ec.Config.Version >= cli.V3 {
|
|
if !cmd.Flags().Changed("datasource") {
|
|
return errors.New("datasource flag is required")
|
|
}
|
|
} else {
|
|
if err := checkIfUpdateToConfigV3IsRequired(ec); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
seedCmd.AddCommand(
|
|
newSeedCreateCmd(ec),
|
|
newSeedApplyCmd(ec),
|
|
)
|
|
|
|
f := seedCmd.PersistentFlags()
|
|
f.StringVar(&ec.Datasource, "datasource", "", "datasource name which operation should be applied")
|
|
|
|
f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine")
|
|
f.String("admin-secret", "", "admin secret for Hasura GraphQL Engine")
|
|
f.String("access-key", "", "access key for Hasura GraphQL Engine")
|
|
f.MarkDeprecated("access-key", "use --admin-secret instead")
|
|
f.Bool("insecure-skip-tls-verify", false, "skip TLS verification and disable cert checking (default: false)")
|
|
f.String("certificate-authority", "", "path to a cert file for the certificate authority")
|
|
|
|
util.BindPFlag(v, "endpoint", f.Lookup("endpoint"))
|
|
util.BindPFlag(v, "admin_secret", f.Lookup("admin-secret"))
|
|
util.BindPFlag(v, "access_key", f.Lookup("access-key"))
|
|
util.BindPFlag(v, "insecure_skip_tls_verify", f.Lookup("insecure-skip-tls-verify"))
|
|
util.BindPFlag(v, "certificate_authority", f.Lookup("certificate-authority"))
|
|
|
|
return seedCmd
|
|
}
|