less verbose processing output

This commit is contained in:
Alex Goodman 2019-02-17 10:24:00 -05:00
parent d4e9bdb806
commit ab3bbb8735
No known key found for this signature in database
GPG Key ID: 743640FAA11698A1
4 changed files with 1 additions and 72 deletions

View File

@ -7,7 +7,6 @@ import (
"path"
"strings"
"github.com/k0kubun/go-ansi"
"github.com/mitchellh/go-homedir"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -42,8 +41,6 @@ func Execute() {
}
func init() {
ansi.CursorHide()
cobra.OnInitialize(initConfig)
cobra.OnInitialize(initLogging)

View File

@ -86,7 +86,6 @@ func (image *dockerImageAnalyzer) Parse(tarFile io.ReadCloser) error {
header, err := tarReader.Next()
if err == io.EOF {
fmt.Println(" ╧")
break
}
@ -191,36 +190,20 @@ func (image *dockerImageAnalyzer) Analyze() (*AnalysisResult, error) {
}, nil
}
// todo: it is bad that this is printing out to the screen. As the interface gets more flushed out, an event update mechanism should be built in (so the caller can format and print updates)
func (image *dockerImageAnalyzer) processLayerTar(name string, layerIdx uint, reader *tar.Reader) error {
tree := filetree.NewFileTree()
tree.Name = name
title := fmt.Sprintf("[layer: %2d]", layerIdx)
message := fmt.Sprintf(" ├─ %s %s ", title, "working...")
fmt.Printf("\r%s", message)
fileInfos, err := image.getFileList(reader)
if err != nil {
return err
}
shortName := name[:15]
pb := utils.NewProgressBar(int64(len(fileInfos)), 30)
for idx, element := range fileInfos {
for _, element := range fileInfos {
tree.FileSize += uint64(element.Size)
// todo: we should check for errors but also allow whiteout files to be not be added (thus not error out)
tree.AddPath(element.Path, element)
if pb.Update(int64(idx)) {
message = fmt.Sprintf(" ├─ %s %s : %s", title, shortName, pb.String())
fmt.Printf("\r%s", message)
}
}
pb.Done()
message = fmt.Sprintf(" ├─ %s %s : %s", title, shortName, pb.String())
fmt.Printf("\r%s\n", message)
image.layerMap[tree.Name] = tree
return nil

View File

@ -3,7 +3,6 @@ package utils
import (
"fmt"
"github.com/jroimartin/gocui"
"github.com/k0kubun/go-ansi"
"github.com/sirupsen/logrus"
"os"
)
@ -31,5 +30,4 @@ func Cleanup() {
if ui != nil {
ui.Close()
}
ansi.CursorShow()
}

View File

@ -1,49 +0,0 @@
package utils
import (
"fmt"
"strings"
)
type progressBar struct {
width int
percent int
rawTotal int64
rawCurrent int64
}
func NewProgressBar(total int64, width int) *progressBar {
return &progressBar{
rawTotal: total,
width: width,
}
}
func (pb *progressBar) Done() {
pb.rawCurrent = pb.rawTotal
pb.percent = 100
}
func (pb *progressBar) Update(currentValue int64) (hasChanged bool) {
pb.rawCurrent = currentValue
percent := int(100.0 * (float64(pb.rawCurrent) / float64(pb.rawTotal)))
if percent != pb.percent {
hasChanged = true
}
pb.percent = percent
return hasChanged
}
func (pb *progressBar) String() string {
done := int((pb.percent * pb.width) / 100.0)
if done > pb.width {
done = pb.width
}
todo := pb.width - done
if todo < 0 {
todo = 0
}
head := 1
return "[" + strings.Repeat("=", done) + strings.Repeat(">", head) + strings.Repeat(" ", todo) + "]" + fmt.Sprintf(" %d %% (%d/%d)", pb.percent, pb.rawCurrent, pb.rawTotal)
}