Do not print empty blocks

This commit is contained in:
maride 2019-12-06 15:23:01 +01:00
parent 77304668ad
commit c2aa435a6d
3 changed files with 33 additions and 14 deletions

15
output/flag.go Normal file
View File

@ -0,0 +1,15 @@
package output
import "flag"
var (
fullOutput *bool
printEmptyBlocks *bool
)
func RegisterFlags() {
fullOutput = flag.Bool("full-output", false, "Show full output instead of limiting submodule output")
printEmptyBlocks = flag.Bool("print-empty-blocks", false, "Prints blocks (submodule output) even if the submodule doesn't have any content to print.")
}

View File

@ -1,24 +1,20 @@
package output
import (
"flag"
"github.com/fatih/color"
)
var (
fullOutput *bool
)
func RegisterFlags() {
fullOutput = flag.Bool("full-output", false, "Show full output instead of limiting submodule output")
}
import "github.com/fatih/color"
// Called at the very end, before terminating pancap
func Finalize() {
printer := color.New(color.Bold, color.BgBlack)
// Check if we snipped, to add a notice how to show the whole block
if DidSnip {
// We snipped - inform user about this process
printer := color.New(color.Bold, color.BgBlack)
printer.Print("\nOutput is snipped at one or more positions. Add --full-output to avoid snipping.")
printer.Println("Output is snipped at one or more positions. Add --full-output to avoid snipping.")
}
// Check if we skipped printing an empty block
if DidAvoidEmptyBlock {
// We did - inform user about this
printer.Println("Some submodule output was hidden. Add --print-empty-blocks to show it.")
}
}

View File

@ -12,12 +12,20 @@ const (
var (
DidSnip bool
DidAvoidEmptyBlock bool
)
// Prints a block of information with the given headline
// If content is empty, printing the headline is omitted.
// If the content is longer than MaxContentLines, content is cut.
func PrintBlock(headline string, content string) {
// Avoid printing empty blocks - at least if user didn't specify it otherwise
if len(content) == 0 && !*printEmptyBlocks {
// No content and we are not forced to print empty blocks, return
DidAvoidEmptyBlock = true
return
}
// Print a newline to add some space between blocks
fmt.Println("")