Skip to content
Open
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
Next Next commit
feat: add configuration for plugin to run go package
  • Loading branch information
frankli0324 committed Oct 30, 2025
commit b8042becc85c008cf522dcab2b6f409d4a860b85
1 change: 1 addition & 0 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func codegen(ctx context.Context, combo config.CombinedSettings, sql OutputPair,
switch {
case plug.Process != nil:
handler = &process.Runner{
GoPkg: plug.Process.GoPkg,
Cmd: plug.Process.Cmd,
Env: plug.Env,
Format: plug.Process.Format,
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type Plugin struct {
Name string `json:"name" yaml:"name"`
Env []string `json:"env" yaml:"env"`
Process *struct {
GoPkg string `json:"go_package" yaml:"go_package"`
Cmd string `json:"cmd" yaml:"cmd"`
Format string `json:"format" yaml:"format"`
} `json:"process" yaml:"process"`
Expand Down
25 changes: 20 additions & 5 deletions internal/ext/process/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

type Runner struct {
GoPkg string
Cmd string
Format string
Env []string
Expand Down Expand Up @@ -53,13 +54,27 @@ func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any,
return fmt.Errorf("unknown plugin format: %s", r.Format)
}

// Check if the output plugin exists
path, err := exec.LookPath(r.Cmd)
if err != nil {
return fmt.Errorf("process: %s not found", r.Cmd)
var cmd *exec.Cmd
switch {
case r.Cmd != "" && r.GoPkg == "":
// Check if the output plugin exists
path, err := exec.LookPath(r.Cmd)
if err != nil {
return fmt.Errorf("process: %s not found", r.Cmd)
}
cmd = exec.CommandContext(ctx, path, method)
case r.Cmd == "" && r.GoPkg != "":
// Check if the go binary exists
path, err := exec.LookPath("go")
if err != nil {
return fmt.Errorf("go binary required to run go package %s", r.GoPkg)
}
cmd = exec.CommandContext(ctx, path, method)
cmd.Args = []string{"run", r.GoPkg}
default:
return fmt.Errorf("cmd and go_package cannot both be empty for process plugin")
}

cmd := exec.CommandContext(ctx, path, method)
cmd.Stdin = bytes.NewReader(stdin)
cmd.Env = []string{
fmt.Sprintf("SQLC_VERSION=%s", info.Version),
Expand Down
Loading