From 3463b55aa453fb5dd3d5e7c6ebf45a3e33710e72 Mon Sep 17 00:00:00 2001 From: Yahav Itzhak Date: Thu, 22 Feb 2024 16:21:55 +0200 Subject: [PATCH] Fix upload and download progress bars (#1125) --- artifactory/commands/generic/upload.go | 4 +- .../transferfiles/state/timeestimation.go | 4 +- .../state/timeestimation_test.go | 32 +++++++------- .../commands/transferfiles/state/utils.go | 4 +- artifactory/utils/storageinfo.go | 34 +++++++------- artifactory/utils/storageinfo_test.go | 12 ++--- artifactory/utils/upload.go | 2 + common/progressbar/filesprogressbar.go | 44 +++++++++---------- common/progressbar/filesprogressbar_test.go | 17 +++---- common/progressbar/readerprogressbar.go | 4 ++ common/progressbar/simpleprogressbar.go | 4 ++ go.mod | 4 +- go.sum | 8 ++-- utils/progressbar/progressbarmng.go | 16 ++++--- 14 files changed, 98 insertions(+), 91 deletions(-) diff --git a/artifactory/commands/generic/upload.go b/artifactory/commands/generic/upload.go index 68f679f0d..b16e83ffd 100644 --- a/artifactory/commands/generic/upload.go +++ b/artifactory/commands/generic/upload.go @@ -200,7 +200,7 @@ func (uc *UploadCommand) upload() (err error) { func getMinChecksumDeploySize() (int64, error) { minChecksumDeploySize := os.Getenv("JFROG_CLI_MIN_CHECKSUM_DEPLOY_SIZE_KB") if minChecksumDeploySize == "" { - return 10240, nil + return services.DefaultMinChecksumDeploy, nil } minSize, err := strconv.ParseInt(minChecksumDeploySize, 10, 64) err = errorutils.CheckError(err) @@ -218,6 +218,8 @@ func getUploadParams(f *spec.File, configuration *utils.UploadConfiguration, bui } uploadParams.Deb = configuration.Deb uploadParams.MinChecksumDeploy = configuration.MinChecksumDeploySize + uploadParams.MinSplitSize = configuration.MinSplitSizeMB * rtServicesUtils.SizeMiB + uploadParams.SplitCount = configuration.SplitCount uploadParams.AddVcsProps = addVcsProps uploadParams.BuildProps = buildProps uploadParams.Archive = f.Archive diff --git a/artifactory/commands/transferfiles/state/timeestimation.go b/artifactory/commands/transferfiles/state/timeestimation.go index d317dcd53..943d5c6b7 100644 --- a/artifactory/commands/transferfiles/state/timeestimation.go +++ b/artifactory/commands/transferfiles/state/timeestimation.go @@ -6,13 +6,13 @@ import ( "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferfiles/api" + "github.com/jfrog/jfrog-client-go/artifactory/services/utils" "github.com/jfrog/jfrog-client-go/utils/log" ) const ( milliSecsInSecond = 1000 - bytesInMB = 1024 * 1024 - bytesPerMilliSecToMBPerSec = float64(milliSecsInSecond) / float64(bytesInMB) + bytesPerMilliSecToMBPerSec = float64(milliSecsInSecond) / float64(utils.SizeMiB) minTransferTimeToShowEstimation = time.Minute * 5 ) diff --git a/artifactory/commands/transferfiles/state/timeestimation_test.go b/artifactory/commands/transferfiles/state/timeestimation_test.go index e4a5da1c4..78c1688eb 100644 --- a/artifactory/commands/transferfiles/state/timeestimation_test.go +++ b/artifactory/commands/transferfiles/state/timeestimation_test.go @@ -5,6 +5,8 @@ import ( "time" "github.com/jfrog/build-info-go/utils" + rtServicesUtils "github.com/jfrog/jfrog-client-go/artifactory/services/utils" + "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "github.com/jfrog/jfrog-cli-core/v2/artifactory/commands/transferfiles/api" @@ -41,9 +43,9 @@ func TestGetSpeed(t *testing.T) { // Chunk 1: one of the files is checksum-deployed chunkStatus1 := api.ChunkStatus{ Files: []api.FileUploadStatusResponse{ - createFileUploadStatusResponse(repo1Key, 10*bytesInMB, false, api.Success), - createFileUploadStatusResponse(repo1Key, 15*bytesInMB, false, api.Success), - createFileUploadStatusResponse(repo1Key, 8*bytesInMB, true, api.Success), + createFileUploadStatusResponse(repo1Key, 10*rtServicesUtils.SizeMiB, false, api.Success), + createFileUploadStatusResponse(repo1Key, 15*rtServicesUtils.SizeMiB, false, api.Success), + createFileUploadStatusResponse(repo1Key, 8*rtServicesUtils.SizeMiB, true, api.Success), }, } addChunkStatus(t, timeEstMng, chunkStatus1, 3, true, 10*milliSecsInSecond) @@ -54,8 +56,8 @@ func TestGetSpeed(t *testing.T) { // Chunk 2: the upload of one of the files failed and the files are not included in the repository's total size (includedInTotalSize == false) chunkStatus2 := api.ChunkStatus{ Files: []api.FileUploadStatusResponse{ - createFileUploadStatusResponse(repo1Key, 21.25*bytesInMB, false, api.Success), - createFileUploadStatusResponse(repo1Key, 6*bytesInMB, false, api.Fail), + createFileUploadStatusResponse(repo1Key, int64(21.25*float64(rtServicesUtils.SizeMiB)), false, api.Success), + createFileUploadStatusResponse(repo1Key, 6*rtServicesUtils.SizeMiB, false, api.Fail), }, } addChunkStatus(t, timeEstMng, chunkStatus2, 2, false, 5*milliSecsInSecond) @@ -85,7 +87,7 @@ func TestGetEstimatedRemainingTimeStringNotAvailableYet(t *testing.T) { // Chunk 1: one of the files is checksum-deployed chunkStatus1 := api.ChunkStatus{ Files: []api.FileUploadStatusResponse{ - createFileUploadStatusResponse(repo1Key, 8*bytesInMB, true, api.Success), + createFileUploadStatusResponse(repo1Key, 8*rtServicesUtils.SizeMiB, true, api.Success), }, } assert.Equal(t, "Not available yet", timeEstMng.GetEstimatedRemainingTimeString()) @@ -119,8 +121,8 @@ func newDefaultTimeEstimationManager(t *testing.T, buildInfoRepos bool) *TimeEst assert.NoError(t, stateManager.SetRepoState(repo1Key, 0, 0, buildInfoRepos, true)) assert.NoError(t, stateManager.SetRepoState(repo2Key, 0, 0, buildInfoRepos, true)) - assert.NoError(t, stateManager.IncTransferredSizeAndFilesPhase1(0, 100*bytesInMB)) - stateManager.OverallTransfer.TotalSizeBytes = 600 * bytesInMB + assert.NoError(t, stateManager.IncTransferredSizeAndFilesPhase1(0, 100*rtServicesUtils.SizeMiB)) + stateManager.OverallTransfer.TotalSizeBytes = 600 * rtServicesUtils.SizeMiB return &TimeEstimationManager{stateManager: stateManager} } @@ -149,7 +151,7 @@ func TestAddingToFullLastSpeedsSlice(t *testing.T) { // Adds a chunk with one non checksum-deployed file and calculates and returns the chunk speed. func addOneFileChunk(t *testing.T, timeEstMng *TimeEstimationManager, workingThreads, chunkDurationMilli, chunkSizeMb int) float64 { chunkDuration := int64(chunkDurationMilli * milliSecsInSecond) - chunkSize := int64(chunkSizeMb * bytesInMB) + chunkSize := int64(chunkSizeMb) * rtServicesUtils.SizeMiB chunkStatus := api.ChunkStatus{ Files: []api.FileUploadStatusResponse{ createFileUploadStatusResponse(repo1Key, chunkSize, false, api.Success), @@ -174,9 +176,9 @@ func TestTransferredSizeInState(t *testing.T) { // Add a chunk of repo1 with multiple successful files, which are included in total. chunkStatus1 := api.ChunkStatus{ Files: []api.FileUploadStatusResponse{ - createFileUploadStatusResponse(repo1Key, 10*bytesInMB, false, api.Success), + createFileUploadStatusResponse(repo1Key, 10*rtServicesUtils.SizeMiB, false, api.Success), // Checksum-deploy should not affect the update size. - createFileUploadStatusResponse(repo1Key, 15*bytesInMB, true, api.Success), + createFileUploadStatusResponse(repo1Key, 15*rtServicesUtils.SizeMiB, true, api.Success), }, } addChunkStatus(t, timeEstMng, chunkStatus1, 3, true, 10*milliSecsInSecond) @@ -184,7 +186,7 @@ func TestTransferredSizeInState(t *testing.T) { // Add another chunk of repo1 which is not included in total. Expected not to be included in update. chunkStatus2 := api.ChunkStatus{ Files: []api.FileUploadStatusResponse{ - createFileUploadStatusResponse(repo1Key, 21*bytesInMB, false, api.Success), + createFileUploadStatusResponse(repo1Key, 21*rtServicesUtils.SizeMiB, false, api.Success), }, } addChunkStatus(t, timeEstMng, chunkStatus2, 3, false, 10*milliSecsInSecond) @@ -195,8 +197,8 @@ func TestTransferredSizeInState(t *testing.T) { // Add a chunk of repo2 which is included in total. The failed file should be ignored. chunkStatus3 := api.ChunkStatus{ Files: []api.FileUploadStatusResponse{ - createFileUploadStatusResponse(repo2Key, 13*bytesInMB, false, api.Success), - createFileUploadStatusResponse(repo2Key, 133*bytesInMB, false, api.Fail), + createFileUploadStatusResponse(repo2Key, 13*rtServicesUtils.SizeMiB, false, api.Success), + createFileUploadStatusResponse(repo2Key, 133*rtServicesUtils.SizeMiB, false, api.Fail), }, } addChunkStatus(t, timeEstMng, chunkStatus3, 3, true, 10*milliSecsInSecond) @@ -205,7 +207,7 @@ func TestTransferredSizeInState(t *testing.T) { // Add one more chunk of repo2. chunkStatus4 := api.ChunkStatus{ Files: []api.FileUploadStatusResponse{ - createFileUploadStatusResponse(repo2Key, 9*bytesInMB, false, api.Success), + createFileUploadStatusResponse(repo2Key, 9*rtServicesUtils.SizeMiB, false, api.Success), }, } addChunkStatus(t, timeEstMng, chunkStatus4, 3, true, 10*milliSecsInSecond) diff --git a/artifactory/commands/transferfiles/state/utils.go b/artifactory/commands/transferfiles/state/utils.go index 8ccc129e4..e1bbdcfeb 100644 --- a/artifactory/commands/transferfiles/state/utils.go +++ b/artifactory/commands/transferfiles/state/utils.go @@ -100,11 +100,11 @@ func GetRepositoryTransferDir(repoKey string) (string, error) { } func getRepositoryHash(repoKey string) (string, error) { - checksumInfo, err := utils.CalcChecksums(strings.NewReader(repoKey), utils.SHA1) + checksums, err := utils.CalcChecksums(strings.NewReader(repoKey), utils.SHA1) if err = errorutils.CheckError(err); err != nil { return "", err } - return checksumInfo[utils.SHA1], nil + return checksums[utils.SHA1], nil } func GetJfrogTransferRepoSubDir(repoKey, subDirName string) (string, error) { diff --git a/artifactory/utils/storageinfo.go b/artifactory/utils/storageinfo.go index bb512bc6b..29f3a7031 100644 --- a/artifactory/utils/storageinfo.go +++ b/artifactory/utils/storageinfo.go @@ -4,6 +4,10 @@ import ( "context" "errors" "fmt" + "strconv" + "strings" + "time" + "github.com/jfrog/gofrog/datastructures" "github.com/jfrog/jfrog-cli-core/v2/utils/config" "github.com/jfrog/jfrog-client-go/artifactory" @@ -11,20 +15,12 @@ import ( clientUtils "github.com/jfrog/jfrog-client-go/utils" "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/jfrog/jfrog-client-go/utils/io/httputils" - "strconv" - "strings" - "time" ) const ( serviceManagerRetriesPerRequest = 3 serviceManagerRetriesWaitPerRequestMilliSecs int = 1000 storageInfoRepoMissingError = "one or more of the requested repositories were not found" - - bytesInKB int64 = 1024 - bytesInMB = 1024 * bytesInKB - bytesInGB = 1024 * bytesInMB - bytesInTB = 1024 * bytesInGB ) var getRepoSummaryPollingTimeout = 10 * time.Minute @@ -171,13 +167,13 @@ func convertStorageSizeStringToBytes(sizeStr string) (int64, error) { case "bytes": sizeInBytes = sizeInUnit case "KB": - sizeInBytes = sizeInUnit * float64(bytesInKB) + sizeInBytes = sizeInUnit * float64(utils.SizeKib) case "MB": - sizeInBytes = sizeInUnit * float64(bytesInMB) + sizeInBytes = sizeInUnit * float64(utils.SizeMiB) case "GB": - sizeInBytes = sizeInUnit * float64(bytesInGB) + sizeInBytes = sizeInUnit * float64(utils.SizeGiB) case "TB": - sizeInBytes = sizeInUnit * float64(bytesInTB) + sizeInBytes = sizeInUnit * float64(utils.SizeTiB) default: return 0, errorutils.CheckErrorf("could not parse size string '%s'", sizeStr) } @@ -185,22 +181,22 @@ func convertStorageSizeStringToBytes(sizeStr string) (int64, error) { } func ConvertIntToStorageSizeString(num int64) string { - if num > bytesInTB { - newNum := float64(num) / float64(bytesInTB) + if num > utils.SizeTiB { + newNum := float64(num) / float64(utils.SizeTiB) stringNum := fmt.Sprintf("%.1f", newNum) return stringNum + "TB" } - if num > bytesInGB { - newNum := float64(num) / float64(bytesInGB) + if num > utils.SizeGiB { + newNum := float64(num) / float64(utils.SizeGiB) stringNum := fmt.Sprintf("%.1f", newNum) return stringNum + "GB" } - if num > bytesInMB { - newNum := float64(num) / float64(bytesInMB) + if num > utils.SizeMiB { + newNum := float64(num) / float64(utils.SizeMiB) stringNum := fmt.Sprintf("%.1f", newNum) return stringNum + "MB" } - newNum := float64(num) / float64(bytesInKB) + newNum := float64(num) / float64(utils.SizeKib) stringNum := fmt.Sprintf("%.1f", newNum) return stringNum + "KB" } diff --git a/artifactory/utils/storageinfo_test.go b/artifactory/utils/storageinfo_test.go index d02cbe9c1..e559f4209 100644 --- a/artifactory/utils/storageinfo_test.go +++ b/artifactory/utils/storageinfo_test.go @@ -69,12 +69,12 @@ func TestConvertStorageSizeStringToBytes(t *testing.T) { expectedSizeBeforeConversion float64 }{ {"bytes", "2.22 bytes", false, 2.22}, - {"KB", "3.333 KB", false, 3.333 * float64(bytesInKB)}, - {"KB with comma", "1,004.64 KB", false, 1004.64 * float64(bytesInKB)}, - {"MB", "4.4444 MB", false, 4.4444 * float64(bytesInMB)}, - {"GB", "5.55555 GB", false, 5.55555 * float64(bytesInGB)}, - {"TB", "6.666666 TB", false, 6.666666 * float64(bytesInTB)}, - {"int", "7 KB", false, 7 * float64(bytesInKB)}, + {"KB", "3.333 KB", false, 3.333 * float64(clientUtils.SizeKib)}, + {"KB with comma", "1,004.64 KB", false, 1004.64 * float64(clientUtils.SizeKib)}, + {"MB", "4.4444 MB", false, 4.4444 * float64(clientUtils.SizeMiB)}, + {"GB", "5.55555 GB", false, 5.55555 * float64(clientUtils.SizeGiB)}, + {"TB", "6.666666 TB", false, 6.666666 * float64(clientUtils.SizeTiB)}, + {"int", "7 KB", false, 7 * float64(clientUtils.SizeKib)}, {"size missing", "8", true, -1}, {"unexpected size", "8 kb", true, -1}, {"too many separators", "8 K B", true, -1}, diff --git a/artifactory/utils/upload.go b/artifactory/utils/upload.go index c9d24382f..11829a5ab 100644 --- a/artifactory/utils/upload.go +++ b/artifactory/utils/upload.go @@ -15,4 +15,6 @@ type UploadConfiguration struct { Threads int MinChecksumDeploySize int64 ExplodeArchive bool + SplitCount int + MinSplitSizeMB int64 } diff --git a/common/progressbar/filesprogressbar.go b/common/progressbar/filesprogressbar.go index 5046c7058..17de11da0 100644 --- a/common/progressbar/filesprogressbar.go +++ b/common/progressbar/filesprogressbar.go @@ -1,7 +1,6 @@ package progressbar import ( - "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" "net/url" "os" "strings" @@ -9,6 +8,8 @@ import ( "sync/atomic" "time" + "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" + "github.com/jfrog/jfrog-cli-core/v2/common/commands" corelog "github.com/jfrog/jfrog-cli-core/v2/utils/log" "github.com/jfrog/jfrog-cli-core/v2/utils/progressbar" @@ -19,8 +20,6 @@ import ( "github.com/vbauerster/mpb/v7/decor" ) -var terminalWidth int - type filesProgressBarManager struct { // A list of progress bar objects. bars []progressBar @@ -74,7 +73,7 @@ func (p *filesProgressBarManager) NewProgressReader(total int64, label, path str mpb.BarRemoveOnComplete(), mpb.AppendDecorators( // Extra chars length is the max length of the KibiByteCounter - decor.Name(buildProgressDescription(label, path, 17)), + decor.Name(buildProgressDescription(label, path, progressbar.GetTerminalWidth(), 17)), decor.CountersKibiByte("%3.1f/%3.1f"), ), ) @@ -87,33 +86,34 @@ func (p *filesProgressBarManager) NewProgressReader(total int64, label, path str return &readerProgressBar } -// Changes progress indicator state and acts accordingly. -func (p *filesProgressBarManager) SetProgressState(id int, state string) { - if state == "Merging" { - p.addNewMergingSpinner(id) - } -} - // Initializes a new progress bar, that replaces the progress bar with the given replacedBarId -func (p *filesProgressBarManager) addNewMergingSpinner(replacedBarId int) { - // Write Lock when appending a new bar to the slice +func (p *filesProgressBarManager) SetMergingState(replacedBarId int, useSpinner bool) (bar ioUtils.Progress) { // Write Lock when appending a new bar to the slice p.barsRWMutex.Lock() defer p.barsRWMutex.Unlock() replacedBar := p.bars[replacedBarId-1].getProgressBarUnit() p.bars[replacedBarId-1].Abort() - newBar := p.container.New(1, - mpb.SpinnerStyle(createSpinnerFramesArray()...).PositionLeft(), + newBar := p.container.New(100, + getMergingProgress(useSpinner), + mpb.BarRemoveOnComplete(), mpb.AppendDecorators( - decor.Name(buildProgressDescription(" Merging ", replacedBar.description, 0)), + decor.Name(buildProgressDescription(" Merging ", replacedBar.description, progressbar.GetTerminalWidth(), 0)), ), ) // Bar replacement is a simple spinner and thus does not implement any read functionality unit := &progressBarUnit{bar: newBar, description: replacedBar.description} progressBar := SimpleProgressBar{progressBarUnit: unit, Id: replacedBarId} p.bars[replacedBarId-1] = &progressBar + return &progressBar +} + +func getMergingProgress(useSpinner bool) mpb.BarFillerBuilder { + if useSpinner { + return mpb.SpinnerStyle(createSpinnerFramesArray()...).PositionLeft() + } + return mpb.BarStyle().Lbound("|").Filler("🟩").Tip("🟩").Padding("⬛").Refiller("").Rbound("|") } -func buildProgressDescription(label, path string, extraCharsLen int) string { +func buildProgressDescription(label, path string, terminalWidth, extraCharsLen int) string { separator := " | " // Max line length after decreasing bar width (*2 in case unicode chars with double width are used) and the extra chars descMaxLength := terminalWidth - (progressbar.ProgressBarWidth*2 + extraCharsLen) @@ -121,15 +121,11 @@ func buildProgressDescription(label, path string, extraCharsLen int) string { } func shortenUrl(path string) string { - if _, err := url.ParseRequestURI(path); err != nil { - return path - } - - semicolonIndex := strings.Index(path, ";") - if semicolonIndex == -1 { + parsedUrl, err := url.ParseRequestURI(path) + if err != nil { return path } - return path[:semicolonIndex] + return strings.TrimPrefix(parsedUrl.Path, "/artifactory") } func buildDescByLimits(descMaxLength int, prefix, path, suffix string) string { diff --git a/common/progressbar/filesprogressbar_test.go b/common/progressbar/filesprogressbar_test.go index 0f9c6fea3..6fa7238a0 100644 --- a/common/progressbar/filesprogressbar_test.go +++ b/common/progressbar/filesprogressbar_test.go @@ -1,22 +1,19 @@ package progressbar import ( - "github.com/jfrog/jfrog-cli-core/v2/utils/progressbar" "testing" + + "github.com/jfrog/jfrog-cli-core/v2/utils/progressbar" + "github.com/stretchr/testify/assert" ) +const terminalWidth = 100 + func TestBuildProgressDescription(t *testing.T) { // Set an arbitrary terminal width - terminalWidth = 100 - tests := getTestCases() - for _, test := range tests { + for _, test := range getTestCases() { t.Run(test.name, func(t *testing.T) { - desc := buildProgressDescription(test.prefix, test.path, test.extraCharsLen) - - // Validate result - if desc != test.expectedDesc { - t.Errorf("Expected value of: \"%s\", got: \"%s\".", test.expectedDesc, desc) - } + assert.Equal(t, test.expectedDesc, buildProgressDescription(test.prefix, test.path, terminalWidth, test.extraCharsLen)) }) } } diff --git a/common/progressbar/readerprogressbar.go b/common/progressbar/readerprogressbar.go index 0ccef8190..fd3a15e64 100644 --- a/common/progressbar/readerprogressbar.go +++ b/common/progressbar/readerprogressbar.go @@ -20,6 +20,10 @@ func (p *ReaderProgressBar) ActionWithProgress(reader io.Reader) (results io.Rea return p.readWithProgress(reader) } +func (p *ReaderProgressBar) SetProgress(progress int64) { + p.bar.SetCurrent(progress) +} + // Abort aborts a progress indicator. Called on both successful and unsuccessful operations func (p *ReaderProgressBar) Abort() { close(p.incrChannel) diff --git a/common/progressbar/simpleprogressbar.go b/common/progressbar/simpleprogressbar.go index a6695acf3..6c363e43a 100644 --- a/common/progressbar/simpleprogressbar.go +++ b/common/progressbar/simpleprogressbar.go @@ -15,6 +15,10 @@ func (p *SimpleProgressBar) ActionWithProgress(reader io.Reader) (results io.Rea return nil } +func (p *SimpleProgressBar) SetProgress(progress int64) { + p.bar.SetCurrent(progress) +} + // Abort aborts a progress indicator. Called on both successful and unsuccessful operations func (p *SimpleProgressBar) Abort() { p.bar.Abort(true) diff --git a/go.mod b/go.mod index 8811b05be..0721ad476 100644 --- a/go.mod +++ b/go.mod @@ -96,8 +96,8 @@ require ( gopkg.in/warnings.v0 v0.1.2 // indirect ) -// replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240218093454-1c352a93c23d +replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240222135341-3cea121c58c7 -// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20231220102935-c8776c613ad8 +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20240222124058-bd9687a8666e // replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.3.3-0.20231223133729-ef57bd08cedc diff --git a/go.sum b/go.sum index eab543fab..246a69e77 100644 --- a/go.sum +++ b/go.sum @@ -83,12 +83,12 @@ github.com/jedib0t/go-pretty/v6 v6.5.4 h1:gOGo0613MoqUcf0xCj+h/V3sHDaZasfv152G6/ github.com/jedib0t/go-pretty/v6 v6.5.4/go.mod h1:5LQIxa52oJ/DlDSLv0HEkWOFMDGoWkJb9ss5KqPpJBg= github.com/jfrog/archiver/v3 v3.6.0 h1:OVZ50vudkIQmKMgA8mmFF9S0gA47lcag22N13iV3F1w= github.com/jfrog/archiver/v3 v3.6.0/go.mod h1:fCAof46C3rAXgZurS8kNRNdSVMKBbZs+bNNhPYxLldI= -github.com/jfrog/build-info-go v1.9.23 h1:+TwUIBEJwRvz9skR8xBfY5ti8Vl4Z6iMCkFbkclnEN0= -github.com/jfrog/build-info-go v1.9.23/go.mod h1:QHcKuesY4MrBVBuEwwBz4uIsX6mwYuMEDV09ng4AvAU= +github.com/jfrog/build-info-go v1.8.9-0.20240222124058-bd9687a8666e h1:NzB2yvEojIhP5KIX9SeCqSljZmoiE98hBzXYvvi52D0= +github.com/jfrog/build-info-go v1.8.9-0.20240222124058-bd9687a8666e/go.mod h1:QHcKuesY4MrBVBuEwwBz4uIsX6mwYuMEDV09ng4AvAU= github.com/jfrog/gofrog v1.6.0 h1:jOwb37nHY2PnxePNFJ6e6279Pgkr3di05SbQQw47Mq8= github.com/jfrog/gofrog v1.6.0/go.mod h1:SZ1EPJUruxrVGndOzHd+LTiwWYKMlHqhKD+eu+v5Hqg= -github.com/jfrog/jfrog-client-go v1.37.1 h1:BqIWGPajC5vhUo5dcQ9KEJr0EVANr/O4cfEqRYvzvRg= -github.com/jfrog/jfrog-client-go v1.37.1/go.mod h1:y+zeO0LeT2uHoHs4/fXHrm5dfF02bg6Dw3cNJxgJ5LY= +github.com/jfrog/jfrog-client-go v1.28.1-0.20240222135341-3cea121c58c7 h1:Xzul3R5zkiAGnay3YumuP0QjqSMXR59wdow+vIy8TN4= +github.com/jfrog/jfrog-client-go v1.28.1-0.20240222135341-3cea121c58c7/go.mod h1:jcZYTyo9H4GtZ6eAYIfKm1ulxeTbshcBBA+YUbWlHNc= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= diff --git a/utils/progressbar/progressbarmng.go b/utils/progressbar/progressbarmng.go index 2c9dce525..4b6e7b523 100644 --- a/utils/progressbar/progressbarmng.go +++ b/utils/progressbar/progressbarmng.go @@ -14,6 +14,7 @@ import ( "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" corelog "github.com/jfrog/jfrog-cli-core/v2/utils/log" "github.com/jfrog/jfrog-client-go/utils" + "github.com/jfrog/jfrog-client-go/utils/errorutils" "github.com/jfrog/jfrog-client-go/utils/log" "github.com/vbauerster/mpb/v7" "github.com/vbauerster/mpb/v7/decor" @@ -33,6 +34,8 @@ const ( GREEN = 1 ) +var terminalWidth int + type ProgressBarMng struct { // A container of all external mpb bar objects to be displayed. container *mpb.Progress @@ -331,20 +334,17 @@ var ShouldInitProgressBar = func() (bool, error) { if !log.IsStdErrTerminal() { return false, err } - err = setTerminalWidthVar() + err = setTerminalWidth() if err != nil { return false, err } return true, nil } -var terminalWidth int - -// Get terminal dimensions -func setTerminalWidthVar() error { +func setTerminalWidth() error { width, _, err := term.GetSize(int(os.Stderr.Fd())) if err != nil { - return err + return errorutils.CheckError(err) } // -5 to avoid edges terminalWidth = width - 5 @@ -353,3 +353,7 @@ func setTerminalWidthVar() error { } return err } + +func GetTerminalWidth() int { + return terminalWidth +}