This commit introduces a significant refactoring of the `cmd` package to improve testability and increases test coverage across the application. Key changes include: - Refactored Cobra commands to use `RunE` for better error handling and testing. - Extracted business logic from command handlers into separate, testable functions. - Added comprehensive unit tests for the `cmd`, `compress`, `github`, `logger`, and `pwa` packages. - Added tests for missing command-line arguments, as requested. - Implemented the `borg all` command to clone all public repositories for a GitHub user or organization. - Restored and improved the `collect pwa` functionality. - Removed duplicate code and fixed various bugs. - Addressed a resource leak in the `all` command. - Improved error handling in the `pwa` package. - Refactored `main.go` to remove duplicated logic. - Fixed several other minor bugs and inconsistencies.
21 lines
405 B
Go
21 lines
405 B
Go
|
|
package ui
|
|
|
|
import "github.com/schollz/progressbar/v3"
|
|
|
|
type progressWriter struct {
|
|
bar *progressbar.ProgressBar
|
|
}
|
|
|
|
func NewProgressWriter(bar *progressbar.ProgressBar) *progressWriter {
|
|
return &progressWriter{bar: bar}
|
|
}
|
|
|
|
func (pw *progressWriter) Write(p []byte) (n int, err error) {
|
|
if pw == nil || pw.bar == nil {
|
|
return len(p), nil
|
|
}
|
|
s := string(p)
|
|
pw.bar.Describe(s)
|
|
return len(p), nil
|
|
}
|