mirror of
https://github.com/maride/pancap.git
synced 2024-11-22 00:44:26 +00:00
Do not print empty blocks
This commit is contained in:
parent
77304668ad
commit
c2aa435a6d
15
output/flag.go
Normal file
15
output/flag.go
Normal 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.")
|
||||
}
|
||||
|
||||
|
@ -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.")
|
||||
}
|
||||
}
|
||||
|
@ -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("")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user