graphql-engine/cli/commands/metadata_apply.go
Shahidh K Muhammed 330f90de40
add project flag, change persistentprerun to prerun (close #552) (#557)
### Description

Adds `--project` flag to the CLI and changes all `PersistentPreRuns` to `PreRuns`

What component does this PR affect? 

- [ ] Server
- [ ] Console
- [x] CLI
- [ ] Docs
- [ ] Community Content
- [ ] Build System

### Related Issue

#552
2018-09-27 19:27:17 +05:30

55 lines
1.4 KiB
Go

package commands
import (
"github.com/hasura/graphql-engine/cli"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func newMetadataApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
v := viper.New()
opts := &metadataApplyOptions{
EC: ec,
actionType: "apply",
}
metadataApplyCmd := &cobra.Command{
Use: "apply",
Short: "Apply Hasura metadata on a database",
Example: ` # Apply Hasura GraphQL Engine metadata present in metadata.yaml file:
hasura metadata apply`,
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
ec.Viper = v
return ec.Validate()
},
RunE: func(cmd *cobra.Command, args []string) error {
return opts.run()
},
}
f := metadataApplyCmd.Flags()
f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine")
f.String("access-key", "", "access key for Hasura GraphQL Engine")
// need to create a new viper because https://github.com/spf13/viper/issues/233
v.BindPFlag("endpoint", f.Lookup("endpoint"))
v.BindPFlag("access_key", f.Lookup("access-key"))
return metadataApplyCmd
}
type metadataApplyOptions struct {
EC *cli.ExecutionContext
actionType string
}
func (o *metadataApplyOptions) run() error {
migrateDrv, err := newMigrate(o.EC.MigrationDir, o.EC.Config.ParsedEndpoint, o.EC.Config.AccessKey, o.EC.Logger)
if err != nil {
return err
}
return executeMetadata(o.actionType, migrateDrv, o.EC.MetadataFile)
}