Skip to content

Commit 61ff4ed

Browse files
author
invoker
committed
fix output
1 parent 5f6b66a commit 61ff4ed

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

main.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,12 +249,19 @@ func writeJSONOutput(results map[string][]string, outputDir string) {
249249
}
250250

251251
if outputDir != "" {
252-
filename := filepath.Join(outputDir, "scan_results.json")
253-
if err := os.WriteFile(filename, jsonData, 0644); err != nil {
252+
// Create directory if it doesn't exist
253+
dir := filepath.Dir(outputDir)
254+
if err := os.MkdirAll(dir, 0755); err != nil {
255+
fmt.Printf("Error creating directory: %v\n", err)
256+
return
257+
}
258+
259+
// Use outputDir directly as it contains the filename
260+
if err := os.WriteFile(outputDir, jsonData, 0644); err != nil {
254261
fmt.Printf("Error writing JSON file: %v\n", err)
255262
return
256263
}
257-
fmt.Printf("📝 Results saved to: %s\n", filename)
264+
fmt.Printf("📝 Results saved to: %s\n", outputDir)
258265
} else {
259266
fmt.Println(string(jsonData))
260267
}
@@ -271,12 +278,19 @@ func writeCSVOutput(results map[string][]string, outputDir string) {
271278
}
272279

273280
if outputDir != "" {
274-
filename := filepath.Join(outputDir, "scan_results.csv")
275-
if err := os.WriteFile(filename, []byte(output.String()), 0644); err != nil {
281+
// Create directory if it doesn't exist
282+
dir := filepath.Dir(outputDir)
283+
if err := os.MkdirAll(dir, 0755); err != nil {
284+
fmt.Printf("Error creating directory: %v\n", err)
285+
return
286+
}
287+
288+
// Use outputDir directly as it contains the filename
289+
if err := os.WriteFile(outputDir, []byte(output.String()), 0644); err != nil {
276290
fmt.Printf("Error writing CSV file: %v\n", err)
277291
return
278292
}
279-
fmt.Printf("📝 Results saved to: %s\n", filename)
293+
fmt.Printf("📝 Results saved to: %s\n", outputDir)
280294
} else {
281295
fmt.Print(output.String())
282296
}

0 commit comments

Comments
 (0)