@@ -250,7 +250,7 @@ var analyzeCmd = &cobra.Command{
250250
251251 log .Println ("Running all configured tools..." )
252252
253- if outputFormat == "sarif" && outputFile != "" {
253+ if outputFormat == "sarif" {
254254 // Create temporary directory for individual tool outputs
255255 tmpDir , err := os .MkdirTemp ("" , "codacy-analysis-*" )
256256 if err != nil {
@@ -266,10 +266,29 @@ var analyzeCmd = &cobra.Command{
266266 sarifOutputs = append (sarifOutputs , tmpFile )
267267 }
268268
269+ // create output file tmp file
270+ tmpOutputFile := filepath .Join (tmpDir , "merged.sarif" )
271+
269272 // Merge all SARIF outputs
270- if err := utils .MergeSarifOutputs (sarifOutputs , outputFile ); err != nil {
273+ if err := utils .MergeSarifOutputs (sarifOutputs , tmpOutputFile ); err != nil {
271274 log .Fatalf ("Failed to merge SARIF outputs: %v" , err )
272275 }
276+
277+ if outputFile != "" {
278+ // copy tmpOutputFile to outputFile
279+ content , err := os .ReadFile (tmpOutputFile )
280+ if err != nil {
281+ log .Fatalf ("Failed to read merged SARIF output: %v" , err )
282+ }
283+ os .WriteFile (outputFile , content , utils .DefaultRW )
284+ } else {
285+ // println the output file content
286+ content , err := os .ReadFile (tmpOutputFile )
287+ if err != nil {
288+ log .Fatalf ("Failed to read merged SARIF output: %v" , err )
289+ }
290+ fmt .Println (string (content ))
291+ }
273292 } else {
274293 // Run tools without merging outputs
275294 for toolName := range tools {
0 commit comments