Skip to content

Commit

Permalink
feat(output): auto-open HTML file after scan
Browse files Browse the repository at this point in the history
  • Loading branch information
hogo6002 committed Nov 20, 2024
1 parent 5e82cf7 commit 804193b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/osv-scanner/scan/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"
"os"
"os/exec"
"runtime"
"slices"
"strings"

Expand Down Expand Up @@ -296,6 +298,23 @@ func action(context *cli.Context, stdout, stderr io.Writer) (reporter.Reporter,
return r, fmt.Errorf("failed to write output: %w", errPrint)
}

// Auto-open outputted HTML file for users.
if outputPath != "" {
if format == "html" {
r.Infof("Opening %s...\n", outputPath)
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", outputPath).Start()
case "windows":
err = exec.Command("start", "", outputPath).Start()
case "darwin": // Add macOS support
err = exec.Command("open", outputPath).Start()
default:
r.Infof("Unsupported platform. Please manually open the outputted HTML file: %s", outputPath)
}
}
}

// This may be nil.
return r, err
}

0 comments on commit 804193b

Please sign in to comment.