Skip to content

Exportable Run function #1204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2021
Merged

Exportable Run function #1204

merged 1 commit into from
Sep 21, 2021

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