Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleconroy committed Nov 6, 2023
1 parent d911277 commit fc384be
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/opts/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"maps"
"path/filepath"

"github.com/sqlc-dev/plugin-sdk-go/plugin"
)
Expand All @@ -16,7 +17,7 @@ type Options struct {
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
EmitEmptySlices bool `json:"emit_empty_slices,omitempty" yaml:"emit_empty_slices"`
EmitExportedQueries bool `json:"emit_exported_queries" yaml:"emit_exported_queries`
EmitExportedQueries bool `json:"emit_exported_queries" yaml:"emit_exported_queries"`
EmitResultStructPointers bool `json:"emit_result_struct_pointers" yaml:"emit_result_struct_pointers"`
EmitParamsStructPointers bool `json:"emit_params_struct_pointers" yaml:"emit_params_struct_pointers"`
EmitMethodsWithDbArgument bool `json:"emit_methods_with_db_argument,omitempty" yaml:"emit_methods_with_db_argument"`
Expand Down Expand Up @@ -77,6 +78,14 @@ func parseOpts(req *plugin.GenerateRequest) (*Options, error) {
return nil, fmt.Errorf("unmarshalling plugin options: %w", err)
}

if options.Package == "" {
if options.Out != "" {
options.Package = filepath.Base(options.Out)
} else {
return nil, fmt.Errorf("invalid options: missing package name")
}
}

for i := range options.Overrides {
if err := options.Overrides[i].parse(req); err != nil {
return nil, err
Expand Down Expand Up @@ -111,6 +120,9 @@ func ValidateOpts(opts *Options) error {
if opts.EmitMethodsWithDbArgument && opts.EmitPreparedQueries {
return fmt.Errorf("invalid options: emit_methods_with_db_argument and emit_prepared_queries options are mutually exclusive")
}
if *opts.QueryParameterLimit < 0 {
return fmt.Errorf("invalid options: query parameter limit must not be negative")
}

return nil
}

0 comments on commit fc384be

Please sign in to comment.