diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 93a6872..094bd83 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -14,10 +14,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install asdf and tools - uses: asdf-vm/actions/install@v1 + uses: asdf-vm/actions/install@v4 - name: Run unit tests run: make test @@ -26,10 +26,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install asdf and tools - uses: asdf-vm/actions/install@v1 + uses: asdf-vm/actions/install@v4 - name: Lint code run: make lint @@ -38,17 +38,17 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install asdf and tools - uses: asdf-vm/actions/install@v1 + uses: asdf-vm/actions/install@v4 - name: Setup python uses: actions/setup-python@v2 with: python-version: '3.x' - - uses: pre-commit/action@v2.0.3 + - uses: pre-commit/action@v3.0.1 with: extra_args: --all-files env: diff --git a/core/output/gauge.go b/core/output/gauge.go index 2278ac3..cd91db1 100644 --- a/core/output/gauge.go +++ b/core/output/gauge.go @@ -22,12 +22,19 @@ const maxProgressBarWidth = 40 // static-status [====> 1/10] (time elapsed 00s) // static-status [============> 3/10] (time elapsed 00s) // static-status [=======================================>10/10] (time elapsed 00s) +// +// It can also include optional trailing context: +// +// static-status [====> 1/10] optional-trailing-status (time elapsed 00s) +// static-status [============> 3/10] optional-trailing-status (time elapsed 00s) +// static-status [=======================================>10/10] optional-trailing-status (time elapsed 00s) type ProgressGauge struct { - status string - current int - capacity int - startTime time.Time - lock sync.RWMutex + status string + trailingStatus string + current int + capacity int + startTime time.Time + lock sync.RWMutex } func (g *ProgressGauge) IsReady() bool { @@ -72,6 +79,15 @@ func (g *ProgressGauge) SetStatus(status string) { g.status = status } +func (g *ProgressGauge) SetTrailingStatus(trailingStatus string) { + if g == nil { + return + } + g.lock.Lock() + defer g.lock.Unlock() + g.trailingStatus = trailingStatus +} + func (g *ProgressGauge) Set(current int) { if g == nil { return @@ -145,11 +161,16 @@ func (g *ProgressGauge) String() string { if spaces < 0 { spaces = 0 } - return fmt.Sprintf(" %s [%s%s%s] (time elapsed %s) ", + progressOutput := fmt.Sprintf(" %s [%s%s%s]", g.status, progressStr, strings.Repeat(" ", spaces), - ratio, + ratio) + if g.trailingStatus != "" { + progressOutput = fmt.Sprintf("%s %s", progressOutput, g.trailingStatus) + } + return fmt.Sprintf("%s (time elapsed %s) ", + progressOutput, duration) } diff --git a/core/output/gauge_test.go b/core/output/gauge_test.go index 625b024..71cbc05 100644 --- a/core/output/gauge_test.go +++ b/core/output/gauge_test.go @@ -46,6 +46,19 @@ func TestProgressGauge(t *testing.T) { assert.Equal(t, " static-status", gauge.String()) gauge.Set(-10) assert.Equal(t, " static-status", gauge.String()) + + // When trailing status is set, it should appear between progress and elapsed-time text. + gauge.Set(3) + gauge.SetTrailingStatus("context-foo") + assert.Equal(t, + " static-status [==========> 3/10] context-foo (time elapsed 01s) ", + gauge.String()) + + // Empty trailing status should preserve existing output format. + gauge.SetTrailingStatus("") + assert.Equal(t, + " static-status [==========> 3/10] (time elapsed 01s) ", + gauge.String()) } func Test_humanReadableDuration(t *testing.T) {