forked from toolshed/abra
feat: add x-platform progress bars for long loads
Closes coop-cloud/organising#150.
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"path"
|
||||
|
||||
"coopcloud.tech/abra/cli/formatter"
|
||||
"coopcloud.tech/abra/pkg/catalogue"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/git"
|
||||
@ -59,15 +60,18 @@ var catalogueGenerateCommand = &cli.Command{
|
||||
|
||||
logrus.Debugf("ensuring '%v' recipe(s) are locally present and up-to-date", len(repos))
|
||||
|
||||
bar := formatter.CreateProgressbar(len(repos), "retrieving recipes...")
|
||||
ch := make(chan string, len(repos))
|
||||
for _, repoMeta := range repos {
|
||||
go func(rm catalogue.RepoMeta) {
|
||||
if recipeName != "" && recipeName != rm.Name {
|
||||
ch <- rm.Name
|
||||
bar.Add(1)
|
||||
return
|
||||
}
|
||||
if _, exists := CatalogueSkipList[rm.Name]; exists {
|
||||
ch <- rm.Name
|
||||
bar.Add(1)
|
||||
return
|
||||
}
|
||||
|
||||
@ -82,6 +86,7 @@ var catalogueGenerateCommand = &cli.Command{
|
||||
}
|
||||
|
||||
ch <- rm.Name
|
||||
bar.Add(1)
|
||||
}(repoMeta)
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
)
|
||||
|
||||
func ShortenID(str string) string {
|
||||
@ -37,3 +38,15 @@ func CreateTable(columns []string) *tablewriter.Table {
|
||||
table.SetHeader(columns)
|
||||
return table
|
||||
}
|
||||
|
||||
// CreateProgressbar generates a progress bar
|
||||
func CreateProgressbar(length int, title string) *progressbar.ProgressBar {
|
||||
return progressbar.NewOptions(
|
||||
length,
|
||||
progressbar.OptionClearOnFinish(),
|
||||
progressbar.OptionSetPredictTime(false),
|
||||
progressbar.OptionShowCount(),
|
||||
progressbar.OptionFullWidth(),
|
||||
progressbar.OptionSetDescription(title),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user