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
|
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
|
// connection validation
|
||||||
func (c *GiteaClient) ValidateConnection(ctx context.Context) error {
|
func (c *GiteaClient) ValidateConnection(ctx context.Context) error {
|
||||||
apiURL := fmt.Sprintf("https://%s/api/v1/user", c.baseURL)
|
apiURL := fmt.Sprintf("https://%s/api/v1/user", c.baseURL)
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,5 @@ func main() {
|
||||||
// manage found repositories
|
// manage found repositories
|
||||||
stats := &GitStats{}
|
stats := &GitStats{}
|
||||||
CheckoutRepositories(repositories, stats)
|
CheckoutRepositories(repositories, stats)
|
||||||
printSummary(stats)
|
printDetailedSummary(stats)
|
||||||
printPullErrorUnstaged(stats)
|
|
||||||
printPullErrorUncommitted(stats)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/k0kubun/go-ansi"
|
"github.com/k0kubun/go-ansi"
|
||||||
"github.com/schollz/progressbar/v3"
|
"github.com/schollz/progressbar/v3"
|
||||||
"github.com/scornet256/go-logger"
|
"github.com/scornet256/go-logger"
|
||||||
|
|
@ -10,6 +9,7 @@ import (
|
||||||
|
|
||||||
var bar *progressbar.ProgressBar
|
var bar *progressbar.ProgressBar
|
||||||
|
|
||||||
|
// make progressbar
|
||||||
func progressBar() {
|
func progressBar() {
|
||||||
|
|
||||||
// configure progressbar
|
// configure progressbar
|
||||||
|
|
@ -31,37 +31,77 @@ func progressBar() {
|
||||||
BarEnd: "]",
|
BarEnd: "]",
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.Print("Initialize progressbar", nil)
|
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
|
// print stats
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"Summary:\n"+
|
"Summary:\n"+
|
||||||
" Cloned repositories: %v\n"+
|
" Cloned repositories: %v\n"+
|
||||||
" Pulled repositories: %v\n"+
|
" Pulled repositories: %v\n"+
|
||||||
" Errors: %v\n",
|
" Errors: %v\n\n",
|
||||||
stats.clonedCount,
|
stats.clonedCount,
|
||||||
stats.pulledCount,
|
stats.pulledCount,
|
||||||
stats.errorCount,
|
stats.errorCount,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// print pull errors unstaged
|
||||||
func printPullErrorUnstaged(stats *GitStats) {
|
func printPullErrorUnstaged(stats *GitStats) {
|
||||||
if len(stats.pullErrorMsgUnstaged) > 0 {
|
if len(stats.pullErrorMsgUnstaged) > 0 {
|
||||||
|
fmt.Println("Repositories with unstaged changes:")
|
||||||
for _, repo := range stats.pullErrorMsgUnstaged {
|
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) {
|
func printPullErrorUncommitted(stats *GitStats) {
|
||||||
if len(stats.pullErrorMsgUncommitted) > 0 {
|
if len(stats.pullErrorMsgUncommitted) > 0 {
|
||||||
|
fmt.Println("Repositories with uncommitted changes:")
|
||||||
for _, repo := range stats.pullErrorMsgUncommitted {
|
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