Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
put json plugin settings in PluginOptions
  • Loading branch information
andrewmbenton committed Oct 11, 2023
commit cd6cebc03636a7450d8736af88134686c537949e
2 changes: 1 addition & 1 deletion internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql outPair, re
if err != nil {
return "", nil, fmt.Errorf("opts marshal failed: %w", err)
}
req.Settings.Codegen.Options = opts
req.PluginOptions = opts

default:
return "", nil, fmt.Errorf("missing language backend")
Expand Down
20 changes: 8 additions & 12 deletions internal/codegen/json/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ import (
)

func parseOptions(req *plugin.CodeGenRequest) (*opts, error) {
if req.Settings == nil {
if len(req.PluginOptions) == 0 {
return new(opts), nil
}
if req.Settings.Codegen != nil {
if len(req.Settings.Codegen.Options) != 0 {
var options *opts
dec := ejson.NewDecoder(bytes.NewReader(req.Settings.Codegen.Options))
dec.DisallowUnknownFields()
if err := dec.Decode(&options); err != nil {
return options, fmt.Errorf("unmarshalling options: %s", err)
}
return options, nil
}

var options *opts
dec := ejson.NewDecoder(bytes.NewReader(req.PluginOptions))
dec.DisallowUnknownFields()
if err := dec.Decode(&options); err != nil {
return options, fmt.Errorf("unmarshalling options: %s", err)
}
return new(opts), nil
return options, nil
}

func Generate(ctx context.Context, req *plugin.CodeGenRequest) (*plugin.CodeGenResponse, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/endtoend/testdata/codegen_json/gen/codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"codegen": {
"out": "",
"plugin": "",
"options": "eyJvdXQiOiJnZW4iLCJpbmRlbnQiOiIgICIsImZpbGVuYW1lIjoiY29kZWdlbi5qc29uIn0="
"options": ""
}
},
"catalog": {
Expand Down Expand Up @@ -65363,5 +65363,5 @@
}
],
"sqlc_version": "v1.22.0",
"plugin_options": ""
"plugin_options": "eyJvdXQiOiJnZW4iLCJpbmRlbnQiOiIgICIsImZpbGVuYW1lIjoiY29kZWdlbi5qc29uIn0="
}