mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
bb63d7e60e
Co-authored-by: Rishichandra Wawhal <rishichandra.wawhal@gmail.com> Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> Co-authored-by: Aravind <aravindkp@outlook.in> Co-authored-by: Anon Ray <ecthiender@users.noreply.github.com> Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
71 lines
2.0 KiB
Go
71 lines
2.0 KiB
Go
package commands
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
|
"github.com/hasura/graphql-engine/cli/util"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
// NewActionsCmd returns the actions command
|
|
func NewActionsCmd(ec *cli.ExecutionContext) *cobra.Command {
|
|
v := viper.New()
|
|
ec.Viper = v
|
|
actionsCmd := &cobra.Command{
|
|
Use: "actions",
|
|
Short: "Manage actions on hasura",
|
|
SilenceUsage: true,
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
err := ec.Prepare()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = ec.Validate()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if ec.Config.Version < cli.V2 {
|
|
return fmt.Errorf("actions commands can be executed only when config version is greater than 1")
|
|
}
|
|
if ec.MetadataDir == "" {
|
|
return fmt.Errorf("actions commands can be executed only when metadata_dir is set in config")
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
actionsCmd.AddCommand(
|
|
newActionsCreateCmd(ec, v),
|
|
newActionsCodegenCmd(ec),
|
|
newActionsUseCodegenCmd(ec),
|
|
)
|
|
|
|
actionsCmd.PersistentFlags().String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine")
|
|
actionsCmd.PersistentFlags().String("admin-secret", "", "admin secret for Hasura GraphQL Engine")
|
|
actionsCmd.PersistentFlags().String("access-key", "", "access key for Hasura GraphQL Engine")
|
|
actionsCmd.PersistentFlags().MarkDeprecated("access-key", "use --admin-secret instead")
|
|
|
|
v.BindPFlag("endpoint", actionsCmd.PersistentFlags().Lookup("endpoint"))
|
|
v.BindPFlag("admin_secret", actionsCmd.PersistentFlags().Lookup("admin-secret"))
|
|
v.BindPFlag("access_key", actionsCmd.PersistentFlags().Lookup("access-key"))
|
|
|
|
return actionsCmd
|
|
}
|
|
|
|
func getCodegenFrameworks() (allFrameworks []codegenFramework, err error) {
|
|
frameworkFileBytes, err := ioutil.ReadFile(filepath.Join(ec.GlobalConfigDir, util.ActionsCodegenDirName, "frameworks.json"))
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = json.Unmarshal(frameworkFileBytes, &allFrameworks)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|