feat: refactor output.go
This commit is contained in:
parent
1fb5591ea6
commit
55dacbfec2
3 changed files with 47 additions and 26 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -67,7 +67,5 @@ func main() {
|
|||
// manage found repositories
|
||||
stats := &GitStats{}
|
||||
CheckoutRepositories(repositories, stats)
|
||||
printSummary(stats)
|
||||
printPullErrorUnstaged(stats)
|
||||
printPullErrorUncommitted(stats)
|
||||
printDetailedSummary(stats)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue