这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions cli/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

const (
defaultDirectory = "hasura"
MANIFESTS_DIR = "install-scripts"
)

// NewInitCmd is the definition for init command
Expand Down Expand Up @@ -62,12 +61,9 @@ type initOptions struct {
}

func (o *initOptions) run() error {
if o.EC.ExecutionDirectory == "" {
o.EC.ExecutionDirectory = o.InitDir
}

var dir string
// prompt for init directory if it's not set already
if len(o.InitDir) == 0 {
if o.InitDir == "" {
p := promptui.Prompt{
Label: "Name of project directory ",
Default: defaultDirectory,
Expand All @@ -77,10 +73,18 @@ func (o *initOptions) run() error {
return handlePromptError(err)
}
if strings.TrimSpace(r) != "" {
o.EC.ExecutionDirectory = r
dir = r
} else {
o.EC.ExecutionDirectory = defaultDirectory
dir = defaultDirectory
}
} else {
dir = o.InitDir
}

if o.EC.ExecutionDirectory == "" {
o.EC.ExecutionDirectory = dir
} else {
o.EC.ExecutionDirectory = filepath.Join(o.EC.ExecutionDirectory, dir)
}

var infoMsg string
Expand Down
13 changes: 0 additions & 13 deletions cli/commands/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,19 @@ import (
"github.com/hasura/graphql-engine/cli/migrate"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func NewMetadataCmd(ec *cli.ExecutionContext) *cobra.Command {
v := viper.New()
metadataCmd := &cobra.Command{
Use: "metadata",
Short: "Manage Hasura GraphQL Engine metdata saved in the database",
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
ec.Viper = v
return ec.Validate()
},
}
metadataCmd.AddCommand(
newMetadataExportCmd(ec),
newMetadataResetCmd(ec),
newMetadataApplyCmd(ec),
)
f := metadataCmd.PersistentFlags()
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 metadataCmd
}

Expand Down
14 changes: 14 additions & 0 deletions cli/commands/metadata_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ 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",
Expand All @@ -17,11 +19,23 @@ func newMetadataApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
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
}

Expand Down
14 changes: 14 additions & 0 deletions cli/commands/metadata_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package commands
import (
"github.com/hasura/graphql-engine/cli"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func newMetadataExportCmd(ec *cli.ExecutionContext) *cobra.Command {
v := viper.New()
opts := &metadataExportOptions{
EC: ec,
actionType: "export",
Expand All @@ -17,11 +19,23 @@ func newMetadataExportCmd(ec *cli.ExecutionContext) *cobra.Command {
Example: ` # Export metadata and save it in metadata.yaml file:
hasura metadata export`,
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 := metadataExportCmd.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 metadataExportCmd
}

Expand Down
14 changes: 14 additions & 0 deletions cli/commands/metadata_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"github.com/hasura/graphql-engine/cli"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func newMetadataResetCmd(ec *cli.ExecutionContext) *cobra.Command {
v := viper.New()
opts := &metadataResetOptions{
EC: ec,
actionType: "reset",
Expand All @@ -18,11 +20,23 @@ func newMetadataResetCmd(ec *cli.ExecutionContext) *cobra.Command {
Example: ` # Clean all the metadata information from database:
hasura metadata reset`,
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 := metadataResetCmd.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 metadataResetCmd
}

Expand Down
13 changes: 0 additions & 13 deletions cli/commands/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,19 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func NewMigrateCmd(ec *cli.ExecutionContext) *cobra.Command {
v := viper.New()
migrateCmd := &cobra.Command{
Use: "migrate",
Short: "Manage migrations on the database",
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
ec.Viper = v
return ec.Validate()
},
}
migrateCmd.AddCommand(
newMigrateApplyCmd(ec),
newMigrateStatusCmd(ec),
newMigrateCreateCmd(ec),
)
f := migrateCmd.PersistentFlags()
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 migrateCmd
}

Expand Down
13 changes: 13 additions & 0 deletions cli/commands/migrate_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ import (
migrate "github.com/hasura/graphql-engine/cli/migrate"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func newMigrateApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
v := viper.New()
opts := &migrateApplyOptions{
EC: ec,
}
migrateApplyCmd := &cobra.Command{
Use: "apply",
Short: "Apply migrations on the database",
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()
},
Expand All @@ -28,6 +34,13 @@ func newMigrateApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
f.StringVar(&opts.downMigration, "down", "", "apply all or N down migration steps")
f.StringVar(&opts.versionMigration, "version", "", "migrate the database to a specific version")
f.StringVar(&opts.migrationType, "type", "up", "type of migration (up, down) to be used with version flag")

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 migrateApplyCmd
}

Expand Down
14 changes: 14 additions & 0 deletions cli/commands/migrate_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ import (
"github.com/hasura/graphql-engine/cli/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func newMigrateStatusCmd(ec *cli.ExecutionContext) *cobra.Command {
v := viper.New()
opts := &migrateStatusOptions{
EC: ec,
}
migrateStatusCmd := &cobra.Command{
Use: "status",
Short: "Display current status of migrations on a database",
SilenceUsage: true,
PreRunE: func(cmd *cobra.Command, args []string) error {
ec.Viper = v
return ec.Validate()
},
RunE: func(cmd *cobra.Command, args []string) error {
status, err := opts.run()
if err != nil {
Expand All @@ -31,6 +37,14 @@ func newMigrateStatusCmd(ec *cli.ExecutionContext) *cobra.Command {
},
}

f := migrateStatusCmd.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 migrateStatusCmd
}

Expand Down
1 change: 1 addition & 0 deletions cli/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func init() {
)
f := rootCmd.PersistentFlags()
f.StringVar(&ec.LogLevel, "log-level", "INFO", "log level (DEBUG, INFO, WARN, ERROR, FATAL)")
f.StringVar(&ec.ExecutionDirectory, "project", "", "directory where commands are executed. (default: current dir)")
}

// Execute executes the command and returns the error
Expand Down