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

Code before:
import (
	"github.com/hasura/graphql-engine/cli"
	"github.com/pkg/errors"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

func newMetadataClearCmd(ec *cli.ExecutionContext) *cobra.Command {
	v := viper.New()
	opts := &metadataClearOptions{
		EC:         ec,
		actionType: "clear",
	}

	metadataResetCmd := &cobra.Command{
		Use:     "clear",
		Aliases: []string{"reset"},
		Short:   "Clear Hasura GraphQL Engine metadata on the database",
		Example: `
		# Clear all the metadata information from database:
  	hasura metadata clear

		# Apply admin secret for Hasura GraphQL Engine:
		hasura metadata clear --admin-secret "<admin-secret>"

		# Add Hasura GraphQL Server endpoint:
		hasura metadata clear --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 {
			if cmd.CalledAs() == "reset" {
				opts.EC.Logger.Warn("metadata reset command is deprecated, use metadata clear instead")
			}
			opts.EC.Spin("Clearing metadata...")
			err := opts.run()
			opts.EC.Spinner.Stop()
			if err != nil {
				return errors.Wrap(err, "failed to clear metadata")
			}
			opts.EC.Logger.Info("Metadata cleared")
			return nil
		},
	}

	f := metadataResetCmd.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")

Review comment (suggestion):
```suggestion
  # Clear metadata on a different Hasura instance:
```

Code after:
import (
	"github.com/hasura/graphql-engine/cli"
	"github.com/pkg/errors"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

func newMetadataClearCmd(ec *cli.ExecutionContext) *cobra.Command {
	v := viper.New()
	opts := &metadataClearOptions{
		EC:         ec,
		actionType: "clear",
	}

	metadataResetCmd := &cobra.Command{
		Use:     "clear",
		Aliases: []string{"reset"},
		Short:   "Clear Hasura GraphQL Engine metadata on the database",
		Example: `  # Clear all the metadata information from database:
  hasura metadata clear

  # Use with admin secret:
  hasura metadata clear --admin-secret "<admin-secret>"

  # Clear metadata on a different Hasura instance:
  hasura metadata clear --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 {
			if cmd.CalledAs() == "reset" {
				opts.EC.Logger.Warn("metadata reset command is deprecated, use metadata clear instead")
			}
			opts.EC.Spin("Clearing metadata...")
			err := opts.run()
			opts.EC.Spinner.Stop()
			if err != nil {
				return errors.Wrap(err, "failed to clear metadata")
			}
			opts.EC.Logger.Info("Metadata cleared")
			return nil
		},
	}

	f := metadataResetCmd.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")