@@ -21,6 +21,7 @@ import (
2121 "github.com/charmbracelet/glamour"
2222 "github.com/kusaridev/kusari-cli/api"
2323 "github.com/kusaridev/kusari-cli/pkg/auth"
24+ "github.com/kusaridev/kusari-cli/pkg/sarif"
2425 urlBuilder "github.com/kusaridev/kusari-cli/pkg/url"
2526)
2627
@@ -39,12 +40,13 @@ var (
3940 workingDir string
4041)
4142
42- func Scan (dir string , rev string , platformUrl string , consoleUrl string , verbose bool , wait bool ) error {
43- return scan (dir , rev , platformUrl , consoleUrl , verbose , wait , false , nil )
43+ func Scan (dir string , rev string , platformUrl string , consoleUrl string , verbose bool , wait bool , outputFormat string ) error {
44+ return scan (dir , rev , platformUrl , consoleUrl , verbose , wait , false , outputFormat , nil )
4445}
4546
4647func RiskCheck (dir string , platformUrl string , consoleUrl string , verbose bool , wait bool ) error {
47- return scan (dir , "" , platformUrl , consoleUrl , verbose , wait , true , nil )
48+ // default to outputformat "markdown" for now for risk check as it will link to console
49+ return scan (dir , "" , platformUrl , consoleUrl , verbose , wait , true , "markdown" , nil )
4850}
4951
5052// scanMock facilitates use of mock values for testing
@@ -55,13 +57,14 @@ type scanMock struct {
5557 token string
5658}
5759
58- func scan (dir string , rev string , platformUrl string , consoleUrl string , verbose bool , wait bool , full bool ,
60+ func scan (dir string , rev string , platformUrl string , consoleUrl string , verbose bool , wait bool , full bool , outputFormat string ,
5961 mock * scanMock ) error {
6062 if verbose {
6163 fmt .Fprintf (os .Stderr , " dir: %s\n " , dir )
6264 fmt .Fprintf (os .Stderr , " rev: %s\n " , rev )
6365 fmt .Fprintf (os .Stderr , " platformUrl: %s\n " , platformUrl )
6466 fmt .Fprintf (os .Stderr , " consoleUrl: %s\n " , consoleUrl )
67+ fmt .Fprintf (os .Stderr , " outputFormat: %s\n " , outputFormat )
6568 }
6669
6770 // Check to see if the directory has a .git directory. If it does not, it is not the root of
@@ -190,7 +193,7 @@ func scan(dir string, rev string, platformUrl string, consoleUrl string, verbose
190193
191194 // Wait for results if the user wants, or exit immediately
192195 if wait {
193- return queryForResult (platformUrl , epoch , accessToken , consoleFullUrl , workspace )
196+ return queryForResult (platformUrl , epoch , accessToken , consoleFullUrl , workspace , outputFormat )
194197 }
195198 return nil
196199}
@@ -199,7 +202,7 @@ func cleanupWorkingDirectory(tempDir string) {
199202 _ = os .RemoveAll (tempDir )
200203}
201204
202- func queryForResult (platformUrl string , epoch * string , accessToken string , consoleFullUrl * string , workspace string ) error {
205+ func queryForResult (platformUrl string , epoch * string , accessToken string , consoleFullUrl * string , workspace , outputFormat string ) error {
203206 maxAttempts := 750
204207 attempt := 0
205208 sleepDuration := time .Second
@@ -262,6 +265,19 @@ func queryForResult(platformUrl string, epoch *string, accessToken string, conso
262265 s .FinalMSG = "✓ Analysis complete!\n "
263266 s .Stop ()
264267
268+ // Check output format
269+ if outputFormat == "sarif" {
270+ // Output sarif format
271+ sarifOutput , err := sarif .ConvertToSARIF (results [0 ].Analysis .RawLLMAnalysis )
272+ if err != nil {
273+ return fmt .Errorf ("failed to convert to SARIF: %w" , err )
274+ }
275+
276+ fmt .Fprintf (os .Stderr , "You can also view your results here: %s\n " , * consoleFullUrl )
277+ fmt .Print (sarifOutput ) // stdout
278+ return nil
279+ }
280+
265281 // Clean and format results for stdout
266282 rawContent := results [0 ].Analysis .Results
267283 cleanedContent := removeImageLines (rawContent )
0 commit comments