@@ -41,7 +41,7 @@ type IssuesOptions struct {
4141func NewCmdIssues () * cobra.Command {
4242 opts := IssuesOptions {
4343 LimitArg : 30 ,
44- OutputFormat : "human " ,
44+ OutputFormat : "pretty " ,
4545 }
4646
4747 doc := heredoc .Docf (`
@@ -81,7 +81,7 @@ func NewCmdIssues() *cobra.Command {
8181 cmd .Flags ().IntVarP (& opts .LimitArg , "limit" , "l" , 30 , "Maximum number of issues to fetch" )
8282
8383 // --output, -o flag
84- cmd .Flags ().StringVarP (& opts .OutputFormat , "output" , "o" , "human " , "Output format: human , table, json, yaml" )
84+ cmd .Flags ().StringVarP (& opts .OutputFormat , "output" , "o" , "pretty " , "Output format: pretty , table, json, yaml" )
8585
8686 // --output-file flag
8787 cmd .Flags ().StringVar (& opts .OutputFile , "output-file" , "" , "Write output to a file instead of stdout" )
@@ -107,7 +107,7 @@ func NewCmdIssues() *cobra.Command {
107107 })
108108 _ = cmd .RegisterFlagCompletionFunc ("output" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
109109 return []string {
110- "human \t Human-readable grouped output" ,
110+ "pretty \t Pretty-printed grouped output" ,
111111 "table\t Table output" ,
112112 "json\t JSON output" ,
113113 "yaml\t YAML output" ,
@@ -360,54 +360,48 @@ func (opts *IssuesOptions) outputTable() error {
360360 return nil
361361 }
362362
363- header := []string {"LOCATION" , "SOURCE" , "ANALYZER" , "CODE" , "TITLE" , "CATEGORY" , "SEVERITY" }
364- data := [][]string {header }
365-
366- terminalWidth := pterm .GetTerminalWidth ()
367- if terminalWidth == 0 {
368- terminalWidth = 120
369- }
363+ showSource := opts .CommitOid != "" || opts .PRNumber > 0
370364
371- colWidths := []int {
372- int (float64 (terminalWidth ) * 0.18 ), // LOCATION
373- int (float64 (terminalWidth ) * 0.08 ), // SOURCE
374- int (float64 (terminalWidth ) * 0.10 ), // ANALYZER
375- int (float64 (terminalWidth ) * 0.10 ), // CODE
376- int (float64 (terminalWidth ) * 0.30 ), // TITLE
377- int (float64 (terminalWidth ) * 0.14 ), // CATEGORY
378- int (float64 (terminalWidth ) * 0.10 ), // SEVERITY
365+ var header []string
366+ if showSource {
367+ header = []string {"LOCATION" , "SOURCE" , "ANALYZER" , "CODE" , "TITLE" , "CATEGORY" , "SEVERITY" }
368+ } else {
369+ header = []string {"LOCATION" , "ANALYZER" , "CODE" , "TITLE" , "CATEGORY" , "SEVERITY" }
379370 }
371+ data := [][]string {header }
380372
381373 cwd , _ := os .Getwd ()
382374
383375 for _ , issue := range opts .issues {
384- filePath := issue .Location .Path
385- if cwd != "" && strings .HasPrefix (filePath , cwd ) {
386- filePath = strings .TrimPrefix (filePath , cwd + "/" )
387- }
388-
389- var issueLocation string
390- if issue .Location .Position .BeginLine == issue .Location .Position .EndLine {
391- issueLocation = fmt .Sprintf ("%s:%d" , filePath , issue .Location .Position .BeginLine )
376+ location := formatLocation (issue , cwd )
377+ severity := formatSeverity (issue .IssueSeverity )
378+ category := humanizeCategory (issue .IssueCategory )
379+ analyzer := analyzerDisplayName (issue .Analyzer )
380+
381+ if showSource {
382+ data = append (data , []string {
383+ location ,
384+ issue .IssueSource ,
385+ analyzer ,
386+ issue .IssueCode ,
387+ issue .IssueText ,
388+ category ,
389+ severity ,
390+ })
392391 } else {
393- issueLocation = fmt .Sprintf ("%s:%d-%d" , filePath , issue .Location .Position .BeginLine , issue .Location .Position .EndLine )
392+ data = append (data , []string {
393+ location ,
394+ analyzer ,
395+ issue .IssueCode ,
396+ issue .IssueText ,
397+ category ,
398+ severity ,
399+ })
394400 }
395-
396- severity := formatSeverity (issue .IssueSeverity )
397-
398- data = append (data , []string {
399- wrapText (issueLocation , colWidths [0 ]),
400- wrapText (issue .IssueSource , colWidths [1 ]),
401- wrapText (issue .Analyzer .Shortcode , colWidths [2 ]),
402- wrapText (issue .IssueCode , colWidths [3 ]),
403- wrapText (issue .IssueText , colWidths [4 ]),
404- wrapText (issue .IssueCategory , colWidths [5 ]),
405- wrapText (severity , colWidths [6 ]),
406- })
407401 }
408402
409- pterm .Println ( pterm . Bold . Sprintf ( "Found %d issue(s)" , len ( opts . issues )) )
410- pterm .DefaultTable . WithHasHeader (). WithBoxed (). WithRowSeparator ( "-" ). WithHeaderRowSeparator ( "-" ). WithData ( data ). Render ( )
403+ pterm .DefaultTable . WithHasHeader (). WithData ( data ). Render ( )
404+ pterm .Printf ( " \n Showing %d issue(s) \n " , len ( opts . issues ) )
411405
412406 return nil
413407}
@@ -536,15 +530,16 @@ func colorSeverity(sev string, text string) string {
536530}
537531
538532func formatSeverity (severity string ) string {
533+ humanized := humanizeSeverity (severity )
539534 switch strings .ToUpper (severity ) {
540535 case "CRITICAL" :
541- return pterm .Red (severity )
536+ return pterm .Red (humanized )
542537 case "MAJOR" :
543- return pterm .LightRed (severity )
538+ return pterm .LightRed (humanized )
544539 case "MINOR" :
545- return pterm .Yellow (severity )
540+ return pterm .Yellow (humanized )
546541 default :
547- return severity
542+ return humanized
548543 }
549544}
550545
@@ -559,52 +554,3 @@ func formatLocation(issue issues.Issue, cwd string) string {
559554 return fmt .Sprintf ("%s:%d-%d" , filePath , issue .Location .Position .BeginLine , issue .Location .Position .EndLine )
560555}
561556
562- func wrapText (text string , maxWidth int ) string {
563- if maxWidth <= 0 {
564- return text
565- }
566-
567- if len (text ) <= maxWidth {
568- return text
569- }
570-
571- words := strings .Fields (text )
572- if len (words ) == 0 {
573- return text
574- }
575-
576- var lines []string
577- var currentLine strings.Builder
578-
579- for _ , word := range words {
580- if currentLine .Len () > 0 && currentLine .Len ()+ len (word )+ 1 > maxWidth {
581- lines = append (lines , currentLine .String ())
582- currentLine .Reset ()
583- }
584-
585- if len (word ) > maxWidth {
586- if currentLine .Len () > 0 {
587- lines = append (lines , currentLine .String ())
588- currentLine .Reset ()
589- }
590- for len (word ) > maxWidth {
591- lines = append (lines , word [:maxWidth ])
592- word = word [maxWidth :]
593- }
594- if len (word ) > 0 {
595- currentLine .WriteString (word )
596- }
597- } else {
598- if currentLine .Len () > 0 {
599- currentLine .WriteString (" " )
600- }
601- currentLine .WriteString (word )
602- }
603- }
604-
605- if currentLine .Len () > 0 {
606- lines = append (lines , currentLine .String ())
607- }
608-
609- return strings .Join (lines , "\n " )
610- }
0 commit comments