Skip to content

Commit c9087ea

Browse files
committed
feat: Log diagnostic and progress to stderr
1 parent 5bc324f commit c9087ea

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

pkg/cmd/scan/output/output.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,10 @@ func GetPrinter(config OutputConfig, quiet bool) output.Printer {
8080

8181
switch config.Key {
8282
case JSONOutputType:
83-
if isStdOut(config.Path) {
84-
return &output.VoidPrinter{}
85-
}
8683
fallthrough
8784
case PlanOutputType:
88-
if isStdOut(config.Path) {
89-
return &output.VoidPrinter{}
90-
}
9185
fallthrough
9286
case HTMLOutputType:
93-
if isStdOut(config.Path) {
94-
return &output.VoidPrinter{}
95-
}
9687
fallthrough
9788
case ConsoleOutputType:
9889
fallthrough

pkg/cmd/scan/output/output_test.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,13 +573,13 @@ func TestGetPrinter(t *testing.T) {
573573
name: "json stdout output",
574574
path: "stdout",
575575
key: JSONOutputType,
576-
want: &output.VoidPrinter{},
576+
want: &output.ConsolePrinter{},
577577
},
578578
{
579579
name: "json /dev/stdout output",
580580
path: "/dev/stdout",
581581
key: JSONOutputType,
582-
want: &output.VoidPrinter{},
582+
want: &output.ConsolePrinter{},
583583
},
584584
{
585585
name: "console stdout output",
@@ -604,25 +604,25 @@ func TestGetPrinter(t *testing.T) {
604604
name: "jsonplan stdout output",
605605
path: "stdout",
606606
key: PlanOutputType,
607-
want: &output.VoidPrinter{},
607+
want: &output.ConsolePrinter{},
608608
},
609609
{
610610
name: "jsonplan /dev/stdout output",
611611
path: "/dev/stdout",
612612
key: PlanOutputType,
613-
want: &output.VoidPrinter{},
613+
want: &output.ConsolePrinter{},
614614
},
615615
{
616616
name: "html stdout output",
617617
path: "stdout",
618618
key: HTMLOutputType,
619-
want: &output.VoidPrinter{},
619+
want: &output.ConsolePrinter{},
620620
},
621621
{
622622
name: "html /dev/stdout output",
623623
path: "/dev/stdout",
624624
key: HTMLOutputType,
625-
want: &output.VoidPrinter{},
625+
want: &output.ConsolePrinter{},
626626
},
627627
}
628628
for _, tt := range tests {
@@ -645,14 +645,14 @@ func TestShouldPrint(t *testing.T) {
645645
want bool
646646
}{
647647
{
648-
name: "test stdout prevents printing",
648+
name: "test stdout should not prevents printing",
649649
outputs: []OutputConfig{
650650
{
651651
Path: "stdout",
652652
Key: JSONOutputType,
653653
},
654654
},
655-
want: false,
655+
want: true,
656656
},
657657
{
658658
name: "test output to file doesn't prevent printing",
@@ -665,7 +665,18 @@ func TestShouldPrint(t *testing.T) {
665665
want: true,
666666
},
667667
{
668-
name: "test stdout prevents printing",
668+
name: "test quiet should prevents printing",
669+
outputs: []OutputConfig{
670+
{
671+
Path: "result.json",
672+
Key: JSONOutputType,
673+
},
674+
},
675+
quiet: true,
676+
want: false,
677+
},
678+
{
679+
name: "test stdout should not prevents printing",
669680
outputs: []OutputConfig{
670681
{
671682
Path: "result.json",
@@ -676,7 +687,7 @@ func TestShouldPrint(t *testing.T) {
676687
Key: PlanOutputType,
677688
},
678689
},
679-
want: false,
690+
want: true,
680691
},
681692
}
682693
for _, tt := range tests {

pkg/output/printer.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package output
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"os"
6+
)
47

58
var globalPrinter Printer = &VoidPrinter{}
69

@@ -23,7 +26,7 @@ func NewConsolePrinter() *ConsolePrinter {
2326
}
2427

2528
func (c *ConsolePrinter) Printf(format string, args ...interface{}) {
26-
fmt.Printf(format, args...)
29+
_, _ = fmt.Fprintf(os.Stderr, format, args...)
2730
}
2831

2932
type VoidPrinter struct{}

0 commit comments

Comments
 (0)