Add CLI progress bars to the packer tool
Since packing can be quite slow, it is nice to display progress to the caller. We use the excellent github.com/vbauerster/mpb library to do so, and add a bit of colour with github.com/logrusru/aurora. Finally, augment the inspector and packer with a summary printer that displays the overall file size/count, and compression ratio for each compression type.
This commit is contained in:
parent
984639d475
commit
6f532296ef
6 changed files with 273 additions and 12 deletions
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
"src.lwithers.me.uk/go/htpack/cmd/htpacker/packer"
|
||||
"src.lwithers.me.uk/go/htpack/packed"
|
||||
)
|
||||
|
||||
var packCmd = &cobra.Command{
|
||||
|
|
@ -89,7 +90,8 @@ func PackFiles(c *cobra.Command, args []string, out string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return packer.Pack(ftp, out)
|
||||
|
||||
return doPack(ftp, out)
|
||||
}
|
||||
|
||||
func PackSpec(c *cobra.Command, spec, out string) error {
|
||||
|
|
@ -103,5 +105,26 @@ func PackSpec(c *cobra.Command, spec, out string) error {
|
|||
return fmt.Errorf("parsing YAML spec %s: %v", spec, err)
|
||||
}
|
||||
|
||||
return packer.Pack(ftp, out)
|
||||
return doPack(ftp, out)
|
||||
}
|
||||
|
||||
func doPack(ftp packer.FilesToPack, out string) error {
|
||||
prog := mpbProgress(ftp)
|
||||
err := packer.Pack2(ftp, out, prog)
|
||||
prog.Complete()
|
||||
|
||||
if err == nil {
|
||||
fin, err := os.Open(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fin.Close()
|
||||
|
||||
_, dir, err := packed.Load(fin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
inspectSummary(dir)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue