Skip to content

Exportable Run function - #1204

Merged
kyleconroy merged 1 commit into
sqlc-dev:mainfrom
oliverpool:patch-1
Sep 21, 2021
Merged

Exportable Run function#1204
kyleconroy merged 1 commit into
sqlc-dev:mainfrom
oliverpool:patch-1

Conversation

@oliverpool

@oliverpool oliverpool commented Sep 21, 2021

Copy link
Copy Markdown
Contributor

Closes #416

This PR adds an exported Run function to the root package.

This allows this library to be simply embedded into other cli apps.

Usage is just like https://github.com/kyleconroy/sqlc/blob/main/cmd/sqlc/main.go :

package main

import (
	"os"

	sqlc "github.com/kyleconroy/sqlc/pkg/cli"
)

func main() {
	os.Exit(sqlc.Run(os.Args[1:], os.Stdin, os.Stdout, os.Stderr))
}

This does not export any internal types, but simply exposes the same interface as the CLI to any go program.


In my case, I have a tool folder in my go project with this file, so that I can run go run ./tool/sqlc.go and be sure to have the right version from the project's go.mod

@kyleconroy kyleconroy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create mirror what eabuild does and create a new pkg/cli package?

https://pkg.go.dev/github.com/evanw/esbuild/pkg/cli

@oliverpool

oliverpool commented Sep 21, 2021

Copy link
Copy Markdown
Contributor Author

@kyleconroy sure, I amended my commit.

@kyleconroy kyleconroy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the stdin, stdout, and stderr arguments? I'd like the exposed function to only take a string slice.

@oliverpool

Copy link
Copy Markdown
Contributor Author

Like this?

@kyleconroy
kyleconroy merged commit 6cea18d into sqlc-dev:main Sep 21, 2021
@oliverpool
oliverpool deleted the patch-1 branch September 21, 2021 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exportable libraries for embedding sqlc functionality in other cli apps

2 participants