Skip to content

Conversation

@oliverpool
Copy link
Contributor

@oliverpool oliverpool commented Sep 21, 2021

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

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

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
Copy link
Contributor Author

oliverpool commented Sep 21, 2021

@kyleconroy sure, I amended my commit.

Copy link
Collaborator

@kyleconroy kyleconroy left a comment

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
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