-
Notifications
You must be signed in to change notification settings - Fork 585
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
I would like a legacy.Execute() without the os.Exit(1) #1435
Comments
Hi @harve106 -- there's an upcoming change to the way the CLI is built; it's this the PR. As part of that, there is a In order to use this, you would just have to write something like: package grype
import (
"github.com/anchore/clio"
"github.com/anchore/grype/cmd/cli"
)
func ExecuteGrype() {
cmd := cli.Command(clio.Identification{
Name: "my-app-name",
Version: "my-app-version",
})
cmd.Execute()
}
Would this solve your issue? |
Not quite, a lot of errors are not fatal and should not trigger an exit of the calling program. Go does not provide a good way for us to allow an OS.exit in a child process without exiting the parent. For certain applications output scraping is desirable, but calling something through a shell scraper is not for numerous reasons. That is the main reason I would like that functionality, to be able to scrape output even if there is an error without killing the parent process. |
I have a PR that implements the functionality I would like with your old method of calling Execute(), #1436 |
Hi @harve106, the aforementioned PR has been merged and you can run grype CLI using this code: package main
import (
"fmt"
"github.com/anchore/clio"
"github.com/anchore/grype/cmd/grype/cli"
)
func executeGrype() {
cmd := cli.Command(clio.Identification{
Name: "my-app-name",
Version: "[not provided]",
})
_ = cmd.Execute()
}
func main() {
executeGrype()
fmt.Println("post-execute")
} It does not call However, I think it would be better to use Grype as a library. I took a stab at this and ended up running into a few issues, but would suggest we look at how to improve the experience of using Grype as a library. Could you expand on your use case at all? |
Hey @harve106, we'll go ahead and close this issue out but please feel free to let us know if you need any more help here. Thanks! |
What would you like to be added:
These lines of code in github.com\anchore\grype@v0.65.1\cmd\grype\cli\legacy\cmd.go
Why is this needed:
I need it in order to use this function as I would the command line app because it's way easier to screen scrape than to go through APIs for simple usage
The text was updated successfully, but these errors were encountered: