Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/state/internal/cmdtree/cmdtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func New(prime *primer.Values, args ...string) *CmdTree {
cveCmd := newCveCommand(prime)
cveCmd.AddChildren(
newReportCommand(prime),
newOpenCommand(prime),
)

exportCmd := newExportCommand(prime)
Expand Down
24 changes: 24 additions & 0 deletions cmd/state/internal/cmdtree/cve.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,27 @@ func newReportCommand(prime *primer.Values) *captain.Command {
},
)
}

func newOpenCommand(prime *primer.Values) *captain.Command {
open := cve.NewOpen(prime)
params := cve.OpenParams{}

return captain.NewCommand(
"open",
locale.Tl("cve_open_title", "Opening Vulnerability Details Page"),
locale.Tl("cve_open_cmd_description", "Open the given vulnerability details in your browser"),
prime.Output(),
prime.Config(),
[]*captain.Flag{},
[]*captain.Argument{
{
Name: locale.Tl("cve_open_id_arg", "ID"),
Description: locale.Tl("cve_open_id_arg_description", "The vulnerablility to open in your browser"),
Value: &params.ID,
},
},
func(_ *captain.Command, _ []string) error {
return open.Run(params)
},
)
}
40 changes: 40 additions & 0 deletions internal/runners/cve/open.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cve

import (
"fmt"

"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/output"
"github.com/skratchdot/open-golang/open"
)

const cveURLPrefix = "https://nvd.nist.gov/vuln/detail/"

type Open struct {
out output.Outputer
}

type OpenParams struct {
ID string
}

func NewOpen(prime primeable) *Open {
return &Open{
out: prime.Output(),
}
}

func (o *Open) Run(params OpenParams) error {
cveURL := fmt.Sprintf("%s%s", cveURLPrefix, params.ID)
err := open.Run(cveURL)
if err != nil {
return errs.AddTips(
locale.WrapError(err, "cve_open_url_err", "Could not open CVE detail URL: {{.V0}}", cveURL),
locale.Tr("browser_fallback", "vulnerability details", cveURL),
)
}
o.out.Print(locale.Tl("cve_open_url", "Vulnerability detail URL: [ACTIONABLE]{{.V0}}[/RESET]", cveURL))

return nil
}
6 changes: 1 addition & 5 deletions internal/runners/ppm/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,7 @@ func (cf *ConversionFlow) openInBrowser(what, url string) {
err := open.Run(url)
if err != nil {
logging.Error("Could not open %s in browser: %v", url, err)
cf.out.Error(locale.Tl(
"ppm_convert_open_browser_fallback",
"Could not open {{.V0}} in your browser.\nYou can copy and paste the following URL manually in the address line of your browser:\n{{.V1}}",
what, url,
))
cf.out.Error(locale.Tr("browser_fallback", what, url))
}
}

Expand Down
2 changes: 2 additions & 0 deletions locale/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1661,3 +1661,5 @@ headless_notify:
Any changes you make are local only and will not be saved the platform. Visit: [ACTIONABLE]{{.V0}}[/RESET] to create a platform project from this commit.

For more information, including how to merge these changes into an existing project, visit: [ACTIONABLE]{{.V1}}[/RESET].
browser_fallback:
other: "Could not open {{.V0}} in your browser.\nYou can copy and paste the following URL manually in the address line of your browser:\n[NOTICE]{{.V1}}[/RESET]"