• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

UiPath / uipathcli / 13284663834

12 Feb 2025 11:48AM UTC coverage: 90.185% (-0.3%) from 90.522%
13284663834

push

github

thschmitt
Download .net runtime for cross-platform Studio Projects

- Added support to extract tar.gz archives which is needed to extract
  dotnet runtime archives on Linux and MacOS
- Downloading the suitable .net runtime when the user uses
  cross-platform Studio projects which allows the uipathcli to work
  without any additional dependencies

81 of 110 new or added lines in 4 files covered. (73.64%)

2 existing lines in 1 file now uncovered.

5072 of 5624 relevant lines covered (90.18%)

1.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/utils/visualization/progress_bar.go
1
package visualization
2

3
import (
4
        "fmt"
5
        "math"
6
        "strings"
7
        "unicode/utf8"
8

9
        "github.com/UiPath/uipathcli/log"
10
)
11

12
// The ProgressBar helps rendering a text-based progress indicator on the command-line.
13
// It uses the standard error output interface of the logger for writing progress.
14
type ProgressBar struct {
15
        logger         log.Logger
16
        renderedLength int
17
}
18

19
func (b *ProgressBar) UpdatePercentage(text string, percent float64) {
1✔
20
        b.logger.LogError("\r")
1✔
21
        length := b.renderTick(text, percent)
1✔
22
        left := b.renderedLength - length
1✔
23
        if left > 0 {
1✔
24
                b.logger.LogError(strings.Repeat(" ", left))
×
25
        }
×
26
        b.renderedLength = length
1✔
27
}
28

29
func (b *ProgressBar) UpdateProgress(text string, current int64, total int64, bytesPerSecond int64) {
1✔
30
        b.logger.LogError("\r")
1✔
31
        length := b.renderProgress(text, current, total, bytesPerSecond)
1✔
32
        left := b.renderedLength - length
1✔
33
        if left > 0 {
2✔
34
                b.logger.LogError(strings.Repeat(" ", left))
1✔
35
        }
1✔
36
        b.renderedLength = length
1✔
37
}
38

39
func (b *ProgressBar) Remove() {
1✔
40
        if b.renderedLength > 0 {
2✔
41
                clear := fmt.Sprintf("\r%s\r", strings.Repeat(" ", b.renderedLength))
1✔
42
                b.logger.LogError(clear)
1✔
43
        }
1✔
44
}
45

46
func (b ProgressBar) renderTick(text string, percent float64) int {
1✔
47
        bar := b.createBar(percent)
1✔
48
        output := fmt.Sprintf("%s      |%s|",
1✔
49
                text,
1✔
50
                bar)
1✔
51
        b.logger.LogError(output)
1✔
52
        return utf8.RuneCountInString(output)
1✔
53
}
1✔
54

55
func (b ProgressBar) renderProgress(text string, currentBytes int64, totalBytes int64, bytesPerSecond int64) int {
1✔
56
        percent := math.Min(float64(currentBytes)/float64(totalBytes)*100.0, 100.0)
1✔
57
        bar := b.createBar(percent)
1✔
58
        totalBytesFormatted, unit := b.formatBytes(totalBytes)
1✔
59
        currentBytesFormatted, unit := b.formatBytesInUnit(currentBytes, unit)
1✔
60
        bytesPerSecondFormatted, bytesPerSecondUnit := b.formatBytes(bytesPerSecond)
1✔
61
        output := fmt.Sprintf("%s %3d%% |%s| (%s/%s %s, %s %s/s)",
1✔
62
                text,
1✔
63
                int(percent),
1✔
64
                bar,
1✔
65
                currentBytesFormatted,
1✔
66
                totalBytesFormatted,
1✔
67
                unit,
1✔
68
                bytesPerSecondFormatted,
1✔
69
                bytesPerSecondUnit)
1✔
70
        b.logger.LogError(output)
1✔
71
        return utf8.RuneCountInString(output)
1✔
72
}
1✔
73

74
func (b ProgressBar) createBar(percent float64) string {
1✔
75
        barCount := int(percent / 5.0)
1✔
76
        if barCount > 20 {
1✔
77
                barCount = 20
×
78
        }
×
79
        return strings.Repeat("█", barCount) + strings.Repeat(" ", 20-barCount)
1✔
80
}
81

82
func (b ProgressBar) formatBytes(count int64) (string, string) {
1✔
83
        if count < 1000 {
2✔
84
                return b.formatBytesInUnit(count, "B")
1✔
85
        }
1✔
86
        if count < 1000*1000 {
2✔
87
                return b.formatBytesInUnit(count, "kB")
1✔
88
        }
1✔
89
        if count < 1000*1000*1000 {
2✔
90
                return b.formatBytesInUnit(count, "MB")
1✔
91
        }
1✔
UNCOV
92
        return b.formatBytesInUnit(count, "GB")
×
93
}
94

95
func (b ProgressBar) formatBytesInUnit(count int64, unit string) (string, string) {
1✔
96
        if unit == "B" {
2✔
97
                return fmt.Sprintf("%d", count), unit
1✔
98
        }
1✔
99
        if unit == "kB" {
2✔
100
                return fmt.Sprintf("%0.1f", float64(count)/1_000), unit
1✔
101
        }
1✔
102
        if unit == "MB" {
2✔
103
                return fmt.Sprintf("%0.1f", float64(count)/1_000_000), unit
1✔
104
        }
1✔
UNCOV
105
        return fmt.Sprintf("%0.1f", float64(count)/1_000_000_000), unit
×
106
}
107

108
func NewProgressBar(logger log.Logger) *ProgressBar {
1✔
109
        return &ProgressBar{logger, 0}
1✔
110
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc