MCPcopy Index your code
hub / github.com/sqlc-dev/sqlc / parseOpts

Function parseOpts

internal/codegen/golang/opts/options.go:80–131  ·  view source on GitHub ↗
(req *plugin.GenerateRequest)

Source from the content-addressed store, hash-verified

78}
79
80func parseOpts(req *plugin.GenerateRequest) (*Options, error) {
81 var options Options
82 if len(req.PluginOptions) == 0 {
83 return &options, nil
84 }
85 if err := json.Unmarshal(req.PluginOptions, &options); err != nil {
86 return nil, fmt.Errorf("unmarshalling plugin options: %w", err)
87 }
88
89 if options.Package == "" {
90 if options.Out != "" {
91 options.Package = filepath.Base(options.Out)
92 } else {
93 return nil, fmt.Errorf("invalid options: missing package name")
94 }
95 }
96
97 for i := range options.Overrides {
98 if err := options.Overrides[i].parse(req); err != nil {
99 return nil, err
100 }
101 }
102
103 if options.SqlPackage != "" {
104 if err := validatePackage(options.SqlPackage); err != nil {
105 return nil, fmt.Errorf("invalid options: %s", err)
106 }
107 }
108
109 if options.SqlDriver != "" {
110 if err := validateDriver(options.SqlDriver); err != nil {
111 return nil, fmt.Errorf("invalid options: %s", err)
112 }
113 }
114
115 if options.QueryParameterLimit == nil {
116 options.QueryParameterLimit = new(int32)
117 *options.QueryParameterLimit = 1
118 }
119
120 if options.Initialisms == nil {
121 options.Initialisms = new([]string)
122 *options.Initialisms = []string{"id"}
123 }
124
125 options.InitialismsMap = map[string]struct{}{}
126 for _, initial := range *options.Initialisms {
127 options.InitialismsMap[initial] = struct{}{}
128 }
129
130 return &options, nil
131}
132
133func parseGlobalOpts(req *plugin.GenerateRequest) (*GlobalOptions, error) {
134 var options GlobalOptions

Callers 1

ParseFunction · 0.85

Calls 3

validatePackageFunction · 0.85
validateDriverFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected