Repository: hasura/graphql-engine
File: cli/commands/migrate_status.go (Go)

Code before:

	"github.com/hasura/graphql-engine/cli"
	"github.com/hasura/graphql-engine/cli/migrate"
	"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",
		Example: `
		# Create migration files from server:
		hasura migrate create "<filename>" --from-server

		# Add admin secret for Hasura GraphQL Engine:
		hasura migrate status --admin-secret "<your-admin-secret>"

		# Add Hasura GraphQL Server endpoint:
		hasura migrate status --endpoint "<http-endpoint>"`,
		SilenceUsage: true,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			ec.Viper = v
			return ec.Validate()
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			opts.EC.Spin("Fetching migration status...")
			status, err := opts.run()
			opts.EC.Spinner.Stop()
			if err != nil {
				return err
			}
			buf := printStatus(status)
			fmt.Println(buf.String())
			return nil
		},
	}

	f := migrateStatusCmd.Flags()
	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")

	// need to create a new viper because https://github.com/spf13/viper/issues/233

Review comment (suggestion):
```suggestion
		hasura migrate status --endpoint "<endpoint>"`,
```

Code after:

	"github.com/hasura/graphql-engine/cli"
	"github.com/hasura/graphql-engine/cli/migrate"
	"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",
		Example: `  # Use with admin secret:
  hasura migrate status --admin-secret "<your-admin-secret>"

  # Check status on a different server:
  hasura migrate status --endpoint "<endpoint>"`,
		SilenceUsage: true,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			ec.Viper = v
			return ec.Validate()
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			opts.EC.Spin("Fetching migration status...")
			status, err := opts.run()
			opts.EC.Spinner.Stop()
			if err != nil {
				return err
			}
			buf := printStatus(status)
			fmt.Println(buf.String())
			return nil
		},
	}

	f := migrateStatusCmd.Flags()
	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")

	// need to create a new viper because https://github.com/spf13/viper/issues/233
	v.BindPFlag("endpoint", f.Lookup("endpoint"))
	v.BindPFlag("admin_secret", f.Lookup("admin-secret"))
	v.BindPFlag("access_key", f.Lookup("access-key"))