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

Code before:
	opts := &metadataDiffOptions{
		EC:     ec,
		output: os.Stdout,
	}

	metadataDiffCmd := &cobra.Command{
		Use:   "diff [file1] [file2]",
		Short: "(PREVIEW) Show a highlighted diff of Hasura metadata",
		Long: `(PREVIEW) Show changes between two different sets of Hasura metadata.
By default, shows changes between exported metadata file and server metadata.`,
		Example: `  # NOTE: This command is in preview, usage and diff format may change.

  # Show changes between server metadata and the exported metadata file:
  hasura metadata diff

  # Show changes between server metadata and that in local_metadata.yaml:
  hasura metadata diff local_metadata.yaml

  # Show changes between metadata from metadata.yaml and metadata_old.yaml:
  hasura metadata diff metadata.yaml metadata_old.yaml

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

	# Add Hasura GraphQL Server endpoint:
	hasura metadata diff --endpoint "<http-endpoint>"`,
		Args: cobra.MaximumNArgs(2),
		PreRunE: func(cmd *cobra.Command, args []string) error {
			ec.Viper = v
			return ec.Validate()
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			messageFormat := "Showing diff between %s and %s..."
			message := ""

			switch len(args) {
			case 0:
				// no args, diff exported metadata and metadata on server
				filename, err := ec.GetExistingMetadataFile()
				if err != nil {
					return errors.Wrap(err, "failed getting metadata file")
				}
				opts.metadata[0] = filename
				message = fmt.Sprintf(messageFormat, filename, "the server")
			case 1:
				// 1 arg, diff given filename and the metadata on server
				opts.metadata[0] = args[0]
				message = fmt.Sprintf(messageFormat, args[0], "the server")
			case 2:
				// 2 args, diff given filenames
				opts.metadata[0] = args[0]

Review comment (suggestion):
```suggestion
  hasura metadata diff --endpoint "<endpoint>"`,
```

Code after:
	opts := &metadataDiffOptions{
		EC:     ec,
		output: os.Stdout,
	}

	metadataDiffCmd := &cobra.Command{
		Use:   "diff [file1] [file2]",
		Short: "(PREVIEW) Show a highlighted diff of Hasura metadata",
		Long: `(PREVIEW) Show changes between two different sets of Hasura metadata.
By default, shows changes between exported metadata file and server metadata.`,
		Example: `  # NOTE: This command is in preview, usage and diff format may change.

  # Show changes between server metadata and the exported metadata file:
  hasura metadata diff

  # Show changes between server metadata and that in local_metadata.yaml:
  hasura metadata diff local_metadata.yaml

  # Show changes between metadata from metadata.yaml and metadata_old.yaml:
  hasura metadata diff metadata.yaml metadata_old.yaml

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

  # Diff metadata on a different Hasura instance:
  hasura metadata diff --endpoint "<endpoint>"`,
		Args: cobra.MaximumNArgs(2),
		PreRunE: func(cmd *cobra.Command, args []string) error {
			ec.Viper = v
			return ec.Validate()
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			messageFormat := "Showing diff between %s and %s..."
			message := ""

			switch len(args) {
			case 0:
				// no args, diff exported metadata and metadata on server
				filename, err := ec.GetExistingMetadataFile()
				if err != nil {
					return errors.Wrap(err, "failed getting metadata file")
				}
				opts.metadata[0] = filename
				message = fmt.Sprintf(messageFormat, filename, "the server")
			case 1:
				// 1 arg, diff given filename and the metadata on server
				opts.metadata[0] = args[0]
				message = fmt.Sprintf(messageFormat, args[0], "the server")
			case 2:
				// 2 args, diff given filenames
				opts.metadata[0] = args[0]