diff --git a/output/flag.go b/output/flag.go new file mode 100644 index 0000000..33595dd --- /dev/null +++ b/output/flag.go @@ -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.") +} + + diff --git a/output/output.go b/output/output.go index e6d01ad..3041c9e 100644 --- a/output/output.go +++ b/output/output.go @@ -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.") } } diff --git a/output/printer.go b/output/printer.go index 9ab2d04..8fa4d28 100644 --- a/output/printer.go +++ b/output/printer.go @@ -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("")