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 package output
import ( import "github.com/fatih/color"
"flag"
"github.com/fatih/color"
)
var (
fullOutput *bool
)
func RegisterFlags() {
fullOutput = flag.Bool("full-output", false, "Show full output instead of limiting submodule output")
}
// Called at the very end, before terminating pancap // Called at the very end, before terminating pancap
func Finalize() { func Finalize() {
printer := color.New(color.Bold, color.BgBlack)
// Check if we snipped, to add a notice how to show the whole block // Check if we snipped, to add a notice how to show the whole block
if DidSnip { if DidSnip {
// We snipped - inform user about this process // We snipped - inform user about this process
printer := color.New(color.Bold, color.BgBlack) printer.Println("Output is snipped at one or more positions. Add --full-output to avoid snipping.")
printer.Print("\nOutput 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 ( var (
DidSnip bool DidSnip bool
DidAvoidEmptyBlock bool
) )
// Prints a block of information with the given headline // Prints a block of information with the given headline
// If content is empty, printing the headline is omitted. // If content is empty, printing the headline is omitted.
// If the content is longer than MaxContentLines, content is cut. // If the content is longer than MaxContentLines, content is cut.
func PrintBlock(headline string, content string) { 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 // Print a newline to add some space between blocks
fmt.Println("") fmt.Println("")