Skip to content

Commit fc384be

Browse files
committed
1 parent d911277 commit fc384be

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

internal/opts/options.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"maps"
7+
"path/filepath"
78

89
"github.com/sqlc-dev/plugin-sdk-go/plugin"
910
)
@@ -16,7 +17,7 @@ type Options struct {
1617
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
1718
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
1819
EmitEmptySlices bool `json:"emit_empty_slices,omitempty" yaml:"emit_empty_slices"`
19-
EmitExportedQueries bool `json:"emit_exported_queries" yaml:"emit_exported_queries`
20+
EmitExportedQueries bool `json:"emit_exported_queries" yaml:"emit_exported_queries"`
2021
EmitResultStructPointers bool `json:"emit_result_struct_pointers" yaml:"emit_result_struct_pointers"`
2122
EmitParamsStructPointers bool `json:"emit_params_struct_pointers" yaml:"emit_params_struct_pointers"`
2223
EmitMethodsWithDbArgument bool `json:"emit_methods_with_db_argument,omitempty" yaml:"emit_methods_with_db_argument"`
@@ -77,6 +78,14 @@ func parseOpts(req *plugin.GenerateRequest) (*Options, error) {
7778
return nil, fmt.Errorf("unmarshalling plugin options: %w", err)
7879
}
7980

81+
if options.Package == "" {
82+
if options.Out != "" {
83+
options.Package = filepath.Base(options.Out)
84+
} else {
85+
return nil, fmt.Errorf("invalid options: missing package name")
86+
}
87+
}
88+
8089
for i := range options.Overrides {
8190
if err := options.Overrides[i].parse(req); err != nil {
8291
return nil, err
@@ -111,6 +120,9 @@ func ValidateOpts(opts *Options) error {
111120
if opts.EmitMethodsWithDbArgument && opts.EmitPreparedQueries {
112121
return fmt.Errorf("invalid options: emit_methods_with_db_argument and emit_prepared_queries options are mutually exclusive")
113122
}
123+
if *opts.QueryParameterLimit < 0 {
124+
return fmt.Errorf("invalid options: query parameter limit must not be negative")
125+
}
114126

115127
return nil
116128
}

0 commit comments

Comments
 (0)