Skip to content

refactor: migrate away from cheggaaa/pb v1#11322

Merged
lidel merged 15 commits into
ipfs:masterfrom
Vinayak9769:master
May 25, 2026
Merged

refactor: migrate away from cheggaaa/pb v1#11322
lidel merged 15 commits into
ipfs:masterfrom
Vinayak9769:master

Conversation

@Vinayak9769
Copy link
Copy Markdown
Contributor

This PR migrates all progress bar usage from github.com/cheggaaa/pb v1 to
github.com/cheggaaa/pb/v3 and aligns progress auto-detection behavior across
commands.

Closes #11316

Changes

  • migrate all progress bar call sites to github.com/cheggaaa/pb/v3
  • update .github/dependabot.yml to ignore the obsolete v1 module path
  • replace removed v1 APIs with their v3 equivalents while preserving existing UX
  • add shared isStderrTTY() handling for cat, get, and add
  • make cat, get, add, and dag export consistently default progress to
    enabled only when stderr is a terminal

@Vinayak9769 Vinayak9769 requested a review from a team as a code owner May 6, 2026 23:02
@Vinayak9769
Copy link
Copy Markdown
Contributor Author

@lidel Hi! Could I get a review on this PR when you have a chance? Thanks! :)

@Vinayak9769
Copy link
Copy Markdown
Contributor Author

Fixed the issue and pushed the changes.

@lidel
Copy link
Copy Markdown
Member

lidel commented May 8, 2026

Thank you for taking a stab at this @Vinayak9769! Would be good to discuss it first in #11316 (pros and cons of this vs other libraries), but since you already did the work this is useful as a data point, thanks!
We will evaluate if v3 is the path to go as part of 0.42 release, parking this until then.

@gammazero gammazero added the status/blocked Unable to be worked further until needs are met label May 12, 2026
lidel added 6 commits May 25, 2026 02:49
Replace three duplicate TTY checks (get.go, dag/export.go, dag/stat.go)
with `cmdenv.IsTerminal(*os.File)` backed by `mattn/go-isatty`.

The helper uses `IsTerminal || IsCygwinTerminal`, which also detects
MSYS2 and Git Bash on Windows. Those terminals expose stdio as a
named pipe rather than a character device, so the previous
`ModeCharDevice` check suppressed the progress bar on real terminals.

- core/commands/cmdenv/tty.go: new helper
- core/commands/{add,cat,get}.go: drop local isStderrTTY
- core/commands/dag/{export,stat}.go: drop inline stat() block
- go.mod: promote mattn/go-isatty to direct (was indirect via pb/v3)
Collapse the explicit-flag-or-TTY-default logic at four call sites
(`cat`, `get`, `dag export`, `dag stat`) into a single helper.
The full bar template (counters, bar, speed, percent, ETA) was
inlined at two call sites in add.go. Move it to a file-level
const.
pb v3's speed element defaults to suffix "%s p/s", so even with
pb.Bytes set, `ipfs add`, `ipfs cat`, `ipfs get`, and
`ipfs dag export` rendered the rate as "713.04 MiB p/s" instead
of "713.04 MiB/s".

Pass explicit format args to the speed and rtime template
elements: rate now renders as "MiB/s", and the unknown-state
fallback reads "?/s" / "ETA ?" instead of bare "?". The four
templates move to package-level consts.
Describe only the user-visible changes; skip library-migration
detail and intermediate-state claims that never shipped.
@lidel
Copy link
Copy Markdown
Member

lidel commented May 25, 2026

Pushed a few follow-up commits:

  • TTY detection now goes through mattn/go-isatty (already a transitive dep), so MSYS2 and Git Bash on Windows are recognized as terminals.
  • Explicit-flag-vs-TTY logic moved to a shared cmdenv.ShouldShowProgress helper across cat, get, dag export, and dag stat.
  • pb v3 templates hoisted to package-level consts; the explicit "%s/s" arg avoids the library's "p/s" default for speed.
  • Changelog entry rewritten to focus on what an upgrading user actually notices.

I'll check on CI tomorrow. There is a lot to improve about progress bars, but we would have to do much deeper refactor. This is a good first step. Once CI is green, let's merge as-is and ship in 0.42.

The `github.com/cheggaaa/pb` (v1) module path is no longer in
`go.mod` after the migration to `pb/v3`, so the ignore rule
never fires.
@lidel lidel removed the status/blocked Unable to be worked further until needs are met label May 25, 2026
@lidel lidel mentioned this pull request May 25, 2026
37 tasks
lidel added 4 commits May 25, 2026 03:41
Match the wording used by `add`, `cat`, and `get`:
"Stream progress data. Defaults to true when stderr is a
terminal."
Call `bar.Finish()` and a final `bar.Write()` after the progress
loop. Without it, fast adds (under ~500ms, where pb/v3's EWMA
never accumulates a speed sample) render `?/s ... ETA ?` in the
last frame. Finishing the bar switches the speed element to its
absolute-rate branch (total/elapsed), so the final frame now
reads e.g. `792.04 MiB/s 100.00% 100ms`.
Exercise the explicit-true, explicit-false, unset, and non-bool
paths. Unset and non-bool fall back to IsTerminal(os.Stderr),
which the test compares against directly so it works in both
TTY and CI environments.
Move the "total known" pb/v3 template to cmdenv.ProgressBarFullTemplate
so add.go and get.go reference the same string instead of keeping
byte-identical local copies. The add init template and dag/export
streaming template stay local because each is single-use and shaped
differently.
Copy link
Copy Markdown
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more follow-ups on top:

  • ipfs add: bar now finalizes properly so the last frame doesn't stick mid-render on fast uploads
  • shared cmdenv.ProgressBarFullTemplate between ipfs add and ipfs get to drop a duplicated template
  • unit test for ShouldShowProgress
  • --progress help text unified across commands
  • dropped unused pb v1 entry from .github/dependabot.yml

Planning to cut v0.42.0-rc1 with this later this/next week.

@lidel lidel merged commit fc865be into ipfs:master May 25, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate away from cheggaaa/pb v1

3 participants