feat: enhance progress bar status handling and alignment#845
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
progressStatusWidthdeclaration as aconstusingmax(...)will not compile in Go since const expressions cannot call functions; consider making it avarinitialized ininit()or hard-coding the computed width. - The comment says status strings are "left-padded", but
fmt.Sprintf("%-*s", ...)right-pads (left-justifies) the text; either update the comment to match the behavior or adjust the format string if you really want left-padding.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `progressStatusWidth` declaration as a `const` using `max(...)` will not compile in Go since const expressions cannot call functions; consider making it a `var` initialized in `init()` or hard-coding the computed width.
- The comment says status strings are "left-padded", but `fmt.Sprintf("%-*s", ...)` right-pads (left-justifies) the text; either update the comment to match the behavior or adjust the format string if you really want left-padding.
## Individual Comments
### Comment 1
<location path="cmd/cli/desktop/progress.go" line_range="247-249" />
<code_context>
displayID = displayID[:12]
}
dockerMsg := jsonstream.Message{
- ID: displayID,
- Status: status,
+ ID: displayID,
+ // Pad status to a fixed width so all progress bars start at the
+ // same column regardless of status string length.
+ Status: fmt.Sprintf("%-*s", progressStatusWidth, status),
</code_context>
<issue_to_address>
**question (bug_risk):** Padding the Status field may affect downstream consumers expecting exact status strings.
Previously `Status` contained the raw value (e.g., "Downloading"), but now it includes trailing spaces for alignment. If any callers or external tools do string equality checks or log `Status` as-is, this change could break them. Please confirm `Status` is only used for display, or consider doing the padding only in the presentation layer (or via a separate display field).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| dockerMsg := jsonstream.Message{ | ||
| ID: displayID, | ||
| Status: status, | ||
| ID: displayID, | ||
| // Pad status to a fixed width so all progress bars start at the |
There was a problem hiding this comment.
question (bug_risk): Padding the Status field may affect downstream consumers expecting exact status strings.
Previously Status contained the raw value (e.g., "Downloading"), but now it includes trailing spaces for alignment. If any callers or external tools do string equality checks or log Status as-is, this change could break them. Please confirm Status is only used for display, or consider doing the padding only in the presentation layer (or via a separate display field).
There was a problem hiding this comment.
Code Review
This pull request replaces hardcoded status strings with constants and introduces a padding mechanism to ensure that progress bars are horizontally aligned in the CLI output. A critical review comment points out that the use of the max built-in function for calculating padding width requires Go 1.21 or later, which may cause build failures if compatibility with older Go versions is required.
| progressStatusWidth = max( | ||
| len(progressStatusWaiting), | ||
| len(progressStatusDownloading), | ||
| len(progressStatusPullComplete), | ||
| len(progressStatusUploading), | ||
| len(progressStatusPushComplete), | ||
| ) |
There was a problem hiding this comment.
Critical
- Compatibility Issue: The
maxbuilt-in function was introduced in Go 1.21. Using it within aconstblock requires the project to be built with Go 1.21 or later. If this CLI tool needs to support older Go versions (which is common for distribution), this will cause a build failure.
Suggested fix: Use a literal constant or a var block with an init() function if compatibility with Go < 1.21 is required.
// progressStatusWidth is the column width to which all status strings
// are left-padded, keeping progress bars horizontally aligned.
progressStatusWidth = 13References
- Pragmatism: Use the simplest viable approach that maintains compatibility with the project's environment. (link)
This pull request improves the progress display logic for Docker operations in the
progress.gofile. The main focus is on standardizing and aligning the status messages in progress updates, making the output more readable and consistent.Progress display improvements:
Waiting,Downloading,Pull complete,Uploading,Push complete) and a computedprogressStatusWidthto ensure all status messages are padded to the same width. This keeps progress bars horizontally aligned in the CLI output.