MCPcopy
hub / github.com/sqlc-dev/sqlc / v2ParseConfig

Function v2ParseConfig

internal/config/v_two.go:10–90  ·  view source on GitHub ↗
(rd io.Reader)

Source from the content-addressed store, hash-verified

8)
9
10func v2ParseConfig(rd io.Reader) (Config, error) {
11 dec := yaml.NewDecoder(rd)
12 dec.KnownFields(true)
13 var conf Config
14 if err := dec.Decode(&conf); err != nil {
15 return conf, err
16 }
17 if conf.Version == "" {
18 return conf, ErrMissingVersion
19 }
20 if conf.Version != "2" {
21 return conf, ErrUnknownVersion
22 }
23 if len(conf.SQL) == 0 {
24 return conf, ErrNoPackages
25 }
26 if err := conf.validateGlobalOverrides(); err != nil {
27 return conf, err
28 }
29 // TODO: Store built-in plugins somewhere else
30 builtins := map[string]struct{}{
31 "go": {},
32 "json": {},
33 }
34 plugins := map[string]struct{}{}
35 for i := range conf.Plugins {
36 if conf.Plugins[i].Name == "" {
37 return conf, ErrPluginNoName
38 }
39 if _, ok := builtins[conf.Plugins[i].Name]; ok {
40 return conf, ErrPluginBuiltin
41 }
42 if _, ok := plugins[conf.Plugins[i].Name]; ok {
43 return conf, ErrPluginExists
44 }
45 if conf.Plugins[i].Process == nil && conf.Plugins[i].WASM == nil {
46 return conf, ErrPluginNoType
47 }
48 if conf.Plugins[i].Process != nil && conf.Plugins[i].WASM != nil {
49 return conf, ErrPluginBothTypes
50 }
51 if conf.Plugins[i].Process != nil {
52 if conf.Plugins[i].Process.Cmd == "" {
53 return conf, ErrPluginProcessNoCmd
54 }
55 }
56 plugins[conf.Plugins[i].Name] = struct{}{}
57 }
58 for j := range conf.SQL {
59 if conf.SQL[j].Engine == "" {
60 return conf, ErrMissingEngine
61 }
62 if conf.SQL[j].Gen.Go != nil {
63 if conf.SQL[j].Gen.Go.Out == "" {
64 return conf, ErrNoPackagePath
65 }
66 }
67 if conf.SQL[j].Gen.JSON != nil {

Callers 1

ParseConfigFunction · 0.85

Calls 1

Tested by

no test coverage detected