MCPcopy Create free account
hub / github.com/nhost/nhost / commandConfigEdit

Function commandConfigEdit

cli/cmd/run/config_edit.go:47–96  ·  view source on GitHub ↗
(ctx context.Context, cmd *cli.Command)

Source from the content-addressed store, hash-verified

45}
46
47func commandConfigEdit(ctx context.Context, cmd *cli.Command) error {
48 ce := clienv.FromCLI(cmd)
49
50 overlayName := cmd.String(flagOverlayName)
51 if overlayName == "" {
52 if err := config.EditFile(
53 ctx, cmd.String(flagEditor), cmd.String(flagConfig),
54 ); err != nil {
55 return fmt.Errorf("failed to edit config: %w", err)
56 }
57
58 return nil
59 }
60
61 if err := os.MkdirAll(ce.Path.RunServiceOverlaysFolder(
62 cmd.String(flagConfig),
63 ), 0o755); err != nil { //nolint:mnd
64 return fmt.Errorf("failed to create json patches directory: %w", err)
65 }
66
67 tmpdir, err := os.MkdirTemp(os.TempDir(), "nhost-jsonpatch")
68 if err != nil {
69 return fmt.Errorf("failed to create temporary directory: %w", err)
70 }
71 defer os.RemoveAll(tmpdir)
72
73 tmpfileName := filepath.Join(tmpdir, "nhost.toml")
74
75 if err := config.CopyConfig[model.ConfigRunServiceConfig](
76 cmd.String(flagConfig),
77 tmpfileName,
78 ce.Path.RunServiceOverlay(cmd.String(flagConfig), overlayName),
79 ); err != nil {
80 return fmt.Errorf("failed to copy config: %w", err)
81 }
82
83 if err := config.EditFile(ctx, cmd.String(flagEditor), tmpfileName); err != nil {
84 return fmt.Errorf("failed to edit config: %w", err)
85 }
86
87 if err := config.GenerateJSONPatch(
88 cmd.String(flagConfig),
89 tmpfileName,
90 ce.Path.RunServiceOverlay(cmd.String(flagConfig), overlayName),
91 ); err != nil {
92 return fmt.Errorf("failed to generate json patch: %w", err)
93 }
94
95 return nil
96}

Callers

nothing calls this directly

Calls 8

FromCLIFunction · 0.92
EditFileFunction · 0.92
CopyConfigFunction · 0.92
GenerateJSONPatchFunction · 0.92
ErrorfMethod · 0.80
RunServiceOverlayMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected