mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 21:16:30 +02:00
Progress bar for refreshing the index
This commit is contained in:
parent
857f692fc6
commit
e410101985
@ -7,8 +7,11 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/vbauerster/mpb/v4"
|
||||
"github.com/vbauerster/mpb/v4/decor"
|
||||
)
|
||||
|
||||
// Index is a representation of the index.toml file for referencing all the files in a pack.
|
||||
@ -153,6 +156,25 @@ func (in *Index) Refresh() error {
|
||||
pathPF, _ := filepath.Abs(in.flags.PackFile)
|
||||
pathIndex, _ := filepath.Abs(in.indexFile)
|
||||
|
||||
progressLength := len(in.Files)
|
||||
progressCurrent := 0
|
||||
progressContainer := mpb.New()
|
||||
progress := progressContainer.AddBar(int64(progressLength),
|
||||
mpb.PrependDecorators(
|
||||
// simple name decorator
|
||||
decor.Name("Refreshing index..."),
|
||||
// decor.DSyncWidth bit enables column width synchronization
|
||||
decor.Percentage(decor.WCSyncSpace),
|
||||
),
|
||||
mpb.AppendDecorators(
|
||||
// replace ETA decorator with "done" message, OnComplete event
|
||||
decor.OnComplete(
|
||||
// ETA decorator with ewma age of 60
|
||||
decor.EwmaETA(decor.ET_STYLE_GO, 60), "done",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
// TODO: A method of specifying pack root directory?
|
||||
// TODO: A method of excluding files
|
||||
packRoot := filepath.Dir(in.flags.PackFile)
|
||||
@ -161,6 +183,16 @@ func (in *Index) Refresh() error {
|
||||
// TODO: Handle errors on individual files properly
|
||||
return err
|
||||
}
|
||||
start := time.Now()
|
||||
defer func() {
|
||||
if progressCurrent >= progressLength {
|
||||
progressLength++
|
||||
progress.SetTotal(int64(progressLength), false)
|
||||
}
|
||||
progressCurrent++
|
||||
progress.Increment(time.Since(start))
|
||||
}()
|
||||
|
||||
// Exit if the files are the same as the pack/index files
|
||||
absPath, _ := filepath.Abs(path)
|
||||
if absPath == pathPF || absPath == pathIndex {
|
||||
@ -177,6 +209,8 @@ func (in *Index) Refresh() error {
|
||||
return err
|
||||
}
|
||||
|
||||
progress.SetTotal(int64(progressLength), true)
|
||||
|
||||
// Check all the files exist, remove them if they don't
|
||||
i := 0
|
||||
for _, file := range in.Files {
|
||||
|
1
go.mod
1
go.mod
@ -4,4 +4,5 @@ require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/mitchellh/mapstructure v1.1.2
|
||||
github.com/urfave/cli v1.20.0
|
||||
github.com/vbauerster/mpb/v4 v4.7.0
|
||||
)
|
||||
|
13
go.sum
13
go.sum
@ -1,6 +1,19 @@
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
|
||||
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
|
||||
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
github.com/vbauerster/mpb/v4 v4.7.0 h1:Et+zVewxG6qmfBf4Ez+nDhLbCSh6WhZrUPHg9a6e+hw=
|
||||
github.com/vbauerster/mpb/v4 v4.7.0/go.mod h1:ugxYn2kSUrY10WK5CWDUZvQxjdwKFN9K3Ja3/z6p4X0=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 h1:p/H982KKEjUnLJkM3tt/LemDnOc1GiZL5FCVlORJ5zo=
|
||||
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872 h1:cGjJzUd8RgBw428LXP65YXni0aiGNA4Bl+ls8SmLOm8=
|
||||
golang.org/x/sys v0.0.0-20190429190828-d89cdac9e872/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
Loading…
x
Reference in New Issue
Block a user