MCPcopy
hub / github.com/hasura/graphql-engine / newMetadataDiffCmd

Function newMetadataDiffCmd

cli/commands/metadata_diff.go:32–87  ·  view source on GitHub ↗
(ec *cli.ExecutionContext)

Source from the content-addressed store, hash-verified

30}
31
32func newMetadataDiffCmd(ec *cli.ExecutionContext) *cobra.Command {
33 opts := &MetadataDiffOptions{
34 EC: ec,
35 Output: ec.Stdout,
36 }
37
38 metadataDiffCmd := &cobra.Command{
39 Use: "diff [file1] [file2]",
40 Short: "(PREVIEW) Show a highlighted diff of the Hasura Metadata",
41 Long: "(PREVIEW) This command shows changes between two different sets of Hasura Metadata. By default, it shows changes between the exported Hasura Metadata and the Hasura Metadata on the server.",
42 Example: ` # NOTE: This command is in preview, usage and diff format may change.
43
44 # Show changes between server metadata and the exported metadata file:
45 hasura metadata diff
46
47# Apply admin secret for Hasura GraphQL Engine:
48 hasura metadata diff --admin-secret "<admin-secret>"
49
50 # Specify a diff type
51 hasura metadata diff --type "unified-json"
52 hasura metadata diff --type "json"
53
54 # Diff metadata on a different Hasura instance:
55 hasura metadata diff --endpoint "<endpoint>"`,
56 Args: cobra.MaximumNArgs(2),
57 PreRunE: func(cmd *cobra.Command, args []string) error {
58 op := genOpName(cmd, "PreRunE")
59 if len(opts.DiffType) > 0 {
60 optsDiffType := DiffType(opts.DiffType)
61 diffTypes := []DiffType{DifftypeJSON, DifftypeYAML, DifftypeUnifiedJSON, DifftypeUnifiedYAML}
62 for _, diffType := range diffTypes {
63 if optsDiffType == diffType {
64 return nil
65 }
66 }
67 return errors.E(op, fmt.Errorf("metadata diff doesn't support difftype %s", optsDiffType))
68 }
69 return nil
70 },
71 RunE: func(cmd *cobra.Command, args []string) error {
72 op := genOpName(cmd, "RunE")
73 opts.Args = args
74 opts.DisableColor = ec.NoColor
75 if err := opts.Run(); err != nil {
76 return errors.E(op, err)
77 }
78 return nil
79 },
80 }
81
82 f := metadataDiffCmd.Flags()
83
84 f.StringVar(&opts.DiffType, "type", "", fmt.Sprintf(`specify a type of diff [allowed values: %v,%v, %v, %v]`, DifftypeUnifiedJSON, DifftypeUnifiedYAML, DifftypeYAML, DifftypeJSON))
85
86 return metadataDiffCmd
87}
88
89func (o *MetadataDiffOptions) Run() error {

Callers 1

NewMetadataCmdFunction · 0.85

Calls 3

RunMethod · 0.95
genOpNameFunction · 0.85
DiffTypeTypeAlias · 0.85

Tested by

no test coverage detected