-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: implement JSON export functionality #2228
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -780,7 +780,8 @@ | |
| } | ||
| }() | ||
|
|
||
| var plainFile, jsonFile, csvFile, indexFile, indexScreenshotFile *os.File | ||
| var plainFile, jsonFile, csvFile, indexFile, indexScreenshotFile, jsonExportFile *os.File | ||
| var jsonExportResults []Result | ||
|
|
||
| if r.options.Output != "" && r.options.OutputAll { | ||
| plainFile = openOrCreateFile(r.options.Resume, r.options.Output) | ||
|
|
@@ -1172,6 +1173,27 @@ | |
| } | ||
| } | ||
|
|
||
| if r.options.JSONExport != "" { | ||
| filename := r.options.JSONExport | ||
|
||
|
|
||
| if jsonExportResults == nil { | ||
| jsonExportResults = make([]Result, 0) | ||
| } | ||
| jsonExportResults = append(jsonExportResults, resp) | ||
|
||
|
|
||
| if jsonExportFile == nil { | ||
| jsonExportFile = openOrCreateFile(r.options.Resume, filename) | ||
| defer func() { | ||
| if jsonExportFile != nil && len(jsonExportResults) > 0 { | ||
| if jsonData, err := json.Marshal(jsonExportResults); err == nil { | ||
| jsonExportFile.Write(jsonData) | ||
| } | ||
| jsonExportFile.Close() | ||
| } | ||
| }() | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if r.options.CSVOutput { | ||
| row := resp.CSVRow(&r.scanopts) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add validation & conflict checks for the new
JSONExportfieldThe option is parsed and stored but never validated.
Consider extending
ValidateOptions()to:-json-exportis combined with streaming JSONL output (-json) – the two formats differ and may confuse users / downstream tooling.Example patch:
@@ func (options *Options) ValidateOptions() error { + // sanity-check json-export + if options.JSONExport != "" { + // reject if used together with json lines + if options.JSONOutput { + return fmt.Errorf("flags -json and -json-export are mutually exclusive") + } + dir := filepath.Dir(options.JSONExport) + if dir != "." && !fileutil.DirExists(dir) { + return fmt.Errorf("directory for json-export (%s) does not exist", dir) + } + if strings.HasSuffix(options.JSONExport, string(os.PathSeparator)) { + return fmt.Errorf("json-export expects a file path, got directory '%s'", options.JSONExport) + } + }This prevents late-runtime errors and clarifies expected usage.
🤖 Prompt for AI Agents