diff --git a/cmd/gogitlabber/gitea.go b/cmd/gogitlabber/gitea.go index 2d63434..f2ff802 100644 --- a/cmd/gogitlabber/gitea.go +++ b/cmd/gogitlabber/gitea.go @@ -180,23 +180,6 @@ func convertGiteaRepositories(giteaRepos []GiteaRepository) []Repository { return repositories } -// update progressbar -func updateProgressBar(repoCount int) error { - if config.Debug { - return nil // Skip progress bar in debug mode - } - - logger.Print("Resetting progress bar", nil) - if err := bar.Set(0); err != nil { - return fmt.Errorf("resetting progress bar: %w", err) - } - - logger.Print("Setting progress bar maximum", nil) - bar.ChangeMax(repoCount) - - return nil -} - // connection validation func (c *GiteaClient) ValidateConnection(ctx context.Context) error { apiURL := fmt.Sprintf("https://%s/api/v1/user", c.baseURL) diff --git a/cmd/gogitlabber/main.go b/cmd/gogitlabber/main.go index e815a1b..b54d2b9 100644 --- a/cmd/gogitlabber/main.go +++ b/cmd/gogitlabber/main.go @@ -67,7 +67,5 @@ func main() { // manage found repositories stats := &GitStats{} CheckoutRepositories(repositories, stats) - printSummary(stats) - printPullErrorUnstaged(stats) - printPullErrorUncommitted(stats) + printDetailedSummary(stats) } diff --git a/cmd/gogitlabber/output.go b/cmd/gogitlabber/output.go index a1a7268..71f4c9a 100644 --- a/cmd/gogitlabber/output.go +++ b/cmd/gogitlabber/output.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "github.com/k0kubun/go-ansi" "github.com/schollz/progressbar/v3" "github.com/scornet256/go-logger" @@ -10,6 +9,7 @@ import ( var bar *progressbar.ProgressBar +// make progressbar func progressBar() { // configure progressbar @@ -31,37 +31,77 @@ func progressBar() { BarEnd: "]", }), ) - logger.Print("Initialize progressbar", nil) } -func printSummary(stats *GitStats) { +// update progressbar +func updateProgressBar(repoCount int) error { + if config.Debug { + return nil // Skip progress bar in debug mode + } + logger.Print("Resetting progress bar", nil) + if err := bar.Set(0); err != nil { + return fmt.Errorf("resetting progress bar: %w", err) + } + logger.Print("Setting progress bar maximum", nil) + bar.ChangeMax(repoCount) + return nil +} +// print summary +func printSummary(stats *GitStats) { // print stats fmt.Println("") fmt.Printf( "Summary:\n"+ " Cloned repositories: %v\n"+ " Pulled repositories: %v\n"+ - " Errors: %v\n", + " Errors: %v\n\n", stats.clonedCount, stats.pulledCount, stats.errorCount, ) } +// print pull errors unstaged func printPullErrorUnstaged(stats *GitStats) { if len(stats.pullErrorMsgUnstaged) > 0 { + fmt.Println("Repositories with unstaged changes:") for _, repo := range stats.pullErrorMsgUnstaged { - fmt.Printf("❕%s has unstaged changes.\n", repo) + fmt.Printf("❕ %s has unstaged changes.\n", repo) } + fmt.Println() } } +// print pull errors uncommited func printPullErrorUncommitted(stats *GitStats) { if len(stats.pullErrorMsgUncommitted) > 0 { + fmt.Println("Repositories with uncommitted changes:") for _, repo := range stats.pullErrorMsgUncommitted { - fmt.Printf("❕%s has uncommitted changes.\n", repo) + fmt.Printf("❕ %s has uncommitted changes.\n", repo) } + fmt.Println() + } +} + +// print errors +func printAllErrors(stats *GitStats) { + printPullErrorUnstaged(stats) + printPullErrorUncommitted(stats) +} + +// check for errors +func hasErrors(stats *GitStats) bool { + return len(stats.pullErrorMsgUnstaged) > 0 || len(stats.pullErrorMsgUncommitted) > 0 +} + +// print detailed summary +func printDetailedSummary(stats *GitStats) { + printSummary(stats) + + if hasErrors(stats) { + fmt.Println("Error Details:") + printAllErrors(stats) } }