diff --git a/cmd/gogitlabber/gitlab.go b/cmd/gogitlabber/gitlab.go index 49b658f..3cb0961 100644 --- a/cmd/gogitlabber/gitlab.go +++ b/cmd/gogitlabber/gitlab.go @@ -58,6 +58,10 @@ func fetchRepositoriesGitlab() ([]Repository, error) { return repositories, fmt.Errorf("ERROR: no repositories found\n") } + repoCount := len(repositories) + bar.Set(0) + bar.ChangeMax(repoCount) + logPrint("HTTP: Returning repositories found", nil) return repositories, nil } diff --git a/cmd/gogitlabber/main.go b/cmd/gogitlabber/main.go index 08d07a8..a214354 100644 --- a/cmd/gogitlabber/main.go +++ b/cmd/gogitlabber/main.go @@ -37,18 +37,18 @@ func main() { } logPrint("VALIDATION: git found in path", nil) + // make initial progressbar + if !debug { + progressBar() + log.SetOutput(io.Discard) + } + // fetch repository information from gitlab repositories, err := fetchRepositoriesGitlab() if err != nil { logFatal("FATAL: %v", err) } - // print progressbar ony if not in debug mode - if !debug { - progressBar(repositories) - log.SetOutput(io.Discard) - } - // manage found repositories checkoutRepositories(repositories, concurrency) printSummary() diff --git a/cmd/gogitlabber/output.go b/cmd/gogitlabber/output.go index 598a476..5fcb74c 100644 --- a/cmd/gogitlabber/output.go +++ b/cmd/gogitlabber/output.go @@ -10,25 +10,18 @@ import ( var bar *progressbar.ProgressBar -func progressBar(repositories []Repository) { - repoCount := len(repositories) +func progressBar() { - // make progressbar - barPrefix := "Getting your one and only repository..." - if repoCount > 1 { - barPrefix = "Getting your repositories..." - } - - bar = progressbar.NewOptions( - repoCount, - progressbar.OptionSetWriter(ansi.NewAnsiStdout()), + // configure progressbar + bar = progressbar.NewOptions(2, progressbar.OptionEnableColorCodes(true), - progressbar.OptionShowCount(), - progressbar.OptionShowDescriptionAtLineEnd(), + progressbar.OptionSetDescription("Logging into Gitlab..."), progressbar.OptionSetElapsedTime(false), progressbar.OptionSetPredictTime(false), progressbar.OptionSetWidth(20), - progressbar.OptionSetDescription(barPrefix), + progressbar.OptionSetWriter(ansi.NewAnsiStdout()), + progressbar.OptionShowCount(), + progressbar.OptionShowDescriptionAtLineEnd(), progressbar.OptionSetTheme(progressbar.Theme{ Saucer: "[green]=[reset]", SaucerHead: "[green]>[reset]", @@ -37,6 +30,14 @@ func progressBar(repositories []Repository) { BarEnd: "]", }), ) + + // initialize progressbar + logPrint("Initialize progressbar", nil) + err := bar.RenderBlank() + progressBarAdd(1) + if err != nil { + logFatal("Initialization of the progressbar failed", err) + } } func progressBarAdd(amount int) {