yoheimuta/protolint

Ability to run protolint from go code

borisrozumnuk opened this issue · 2 comments

Hi @yoheimuta !

It would be great if you can add the ability to run protolint from go code

Or maybe you can provide your vision of how it should be implemented (if it should) and I can make a pull request.

Hi @borisrozumnuk ! Thank you for your suggestion.

Creating a new package that calls internal/cmd in the same way as cmd/protolint/main.go does would be ideal.

My suggestion is to add a top-level package called "lib," which would include a file called "lint.go." Of course, the choice of arguments and handling of results would depend on your specific use case.

new file:   lib/lint.go
package lib

import (
	"bytes"
	"fmt"

	"github.com/yoheimuta/protolint/internal/cmd"
)

func Lint() {
	args := []string{"arg1", "arg2"}

	var stdout bytes.Buffer
	var stderr bytes.Buffer

	exitCode := cmd.Do(args, &stdout, &stderr)

	fmt.Printf("Exit code: %d\n", exitCode)
	fmt.Printf("stdout: %s\n", stdout.String())
	fmt.Printf("stderr: %s\n", stderr.String())
}

If you could make a pull request with these changes, it would be much appreciated.

@borisrozumnuk I added some test code and the usage document, and I just released version 0.43.0.
Thanks 👍