From dd77323f645980166e618ec3889fb6aab4c52012 Mon Sep 17 00:00:00 2001 From: Holly Gong <39108850+hogo6002@users.noreply.github.com> Date: Fri, 6 Dec 2024 09:18:42 +1100 Subject: [PATCH] fix: set format to HTML when requesting serving resutls (#1424) When `serve` is enabled, set the `format` to html (regardless of the `output` flag). --- cmd/osv-scanner/scan/main.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/osv-scanner/scan/main.go b/cmd/osv-scanner/scan/main.go index cdfe615979..bf763f3b15 100644 --- a/cmd/osv-scanner/scan/main.go +++ b/cmd/osv-scanner/scan/main.go @@ -214,18 +214,20 @@ func action(context *cli.Context, stdout, stderr io.Writer) (reporter.Reporter, outputPath := context.String("output") serve := context.Bool("serve") - if serve && outputPath == "" { + if serve { format = "html" - // Create a temporary directory - tmpDir, err := os.MkdirTemp("", "osv-scanner-result") - if err != nil { - return nil, fmt.Errorf("failed creating temporary directory: %w\n"+ - "Please use `--output result.html` to specify the output path", err) - } + if outputPath == "" { + // Create a temporary directory + tmpDir, err := os.MkdirTemp("", "osv-scanner-result") + if err != nil { + return nil, fmt.Errorf("failed creating temporary directory: %w\n"+ + "Please use `--output result.html` to specify the output path", err) + } - // Remove the created temporary directory after - defer os.RemoveAll(tmpDir) - outputPath = filepath.Join(tmpDir, "index.html") + // Remove the created temporary directory after + defer os.RemoveAll(tmpDir) + outputPath = filepath.Join(tmpDir, "index.html") + } } termWidth := 0