Skip to content

update help with pager - #1276

Merged
Andriy Knysh (aknysh) merged 18 commits into
mainfrom
feature/dev-3299-add-pager-to-help
Jun 29, 2025
Merged

Andriy Knysh (aknysh) merged 18 commits into
mainfrom
feature/dev-3299-add-pager-to-help

Conversation

@samtholiya

@samtholiya Sam Tholiya (samtholiya) commented May 31, 2025 •

Copy link
Copy Markdown
Contributor

what

  • Updated help with pager
    image

why

  • Makes easier for users to view the content

references

Summary by CodeRabbit

  • New Features

    • Enhanced help command output with improved formatting and paging for easier reading in the terminal.
    • Help text now adapts to terminal size, displaying content directly or using a pager interface as needed.
    • Added terminal size detection to optimize content display based on terminal dimensions.
    • Introduced styled text output functions supporting flexible output destinations.
  • Bug Fixes

    • More accurate handling of styled and colored text in terminal output.
  • Tests

    • Added comprehensive tests for terminal size detection and content fitting logic to ensure reliable display behavior.
    • Introduced tests covering pager behavior under various terminal conditions and error scenarios.

Comment thread pkg/pager/term_size.go Fixed
Comment thread pkg/pager/term_size.go Fixed
Comment thread pkg/pager/term_size.go Fixed
Comment thread pkg/pager/term_size.go Fixed
Comment thread pkg/pager/term_size.go Fixed
Comment thread pkg/pager/term_size.go Fixed
Comment thread pkg/pager/term_size.go Fixed
Comment thread pkg/pager/term_size.go Fixed
Comment thread pkg/pager/term_size_test.go Fixed
Comment thread pkg/pager/term_size_test.go Fixed
@samtholiya Sam Tholiya (samtholiya) added the minor New features that do not break anything label Jun 1, 2025
@codecov

codecov Bot commented Jun 1, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 81.69014% with 26 lines in your changes missing coverage. Please review.

Project coverage is 51.37%. Comparing base (1a0fac2) to head (9c7dc69).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/root.go 0.00% 15 Missing ⚠️
pkg/pager/pager.go 75.86% 6 Missing and 1 partial ⚠️
internal/tui/utils/utils.go 0.00% 2 Missing ⚠️
pkg/pager/term_size.go 97.91% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1276      +/-   ##
==========================================
- Coverage   51.37%   51.37%   -0.01%     
==========================================
  Files         243      244       +1     
  Lines       26295    26423     +128     
==========================================
+ Hits        13510    13574      +64     
- Misses      11114    11186      +72     
+ Partials     1671     1663       -8     
Flag Coverage Δ
unittests 51.37% <81.69%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samtholiya
Sam Tholiya (samtholiya) marked this pull request as ready for review June 1, 2025 15:11
@samtholiya
Sam Tholiya (samtholiya) requested a review from a team as a code owner June 1, 2025 15:11
@coderabbitai

coderabbitai Bot commented Jun 1, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This change introduces a terminal-aware pager for the help command. It detects if the output fits the terminal viewport and conditionally invokes a pager UI. Terminal size and content fitting logic are abstracted for extensibility and testability, with comprehensive tests for display width and ANSI sequence handling.

Changes

File(s) Change Summary
cmd/root.go Refactored help command logic: buffers styled output, checks TTY, pipes help through pager, adds conditional formatting.
internal/tui/utils/utils.go Added PrintStyledTextToSpecifiedOutput to write styled text to any io.Writer.
pkg/pager/pager.go Added terminal fit and TTY detection to pager; bypasses pager UI if not needed; updated control flow.
pkg/pager/term_size.go New file: Terminal size abstraction, content fitting logic, display width calculation, ANSI escape handling.
pkg/pager/term_size_test.go New file: Unit and integration tests for terminal sizing, content fitting, display width, and ANSI handling.
pkg/pager/pager_test.go New file: Unit tests for pager control flow, TTY detection, content fitting, and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Pager
    participant Terminal

    User->>CLI: Run help command
    CLI->>Terminal: Is stdout TTY?
    alt Not TTY
        CLI->>CLI: Print help output directly
    else TTY
        CLI->>Pager: Does content fit terminal?
        alt Fits
            CLI->>CLI: Print help output directly
        else Does not fit
            CLI->>Pager: Start pager UI
            Pager->>User: Display paged help
        end
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Add pager to help command, only load pager if content exceeds TTY height (DEV-3299) ✅
Pager should support forcing color via config or ENV (DEV-3299) ❓ No explicit implementation for forced color observed.
Use bubbles go modules for pager (DEV-3299) ✅

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
None found

Suggested reviewers

  • Benbentwo
  • aknysh

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5206bd and b649f37.

📒 Files selected for processing (1)
  • pkg/pager/pager_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/pager/pager_test.go
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Build (ubuntu-latest, linux)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Summary
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch feature/dev-3299-add-pager-to-help

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (1)
pkg/pager/term_size.go (1)

131-172: ANSI sequence parsing is thorough but complex.

The ANSI sequence handling covers the main cases (CSI sequences, character sets). The logic appears correct for skipping these non-printable sequences.

Note: Static analysis flagged the cyclomatic complexity of skipAnsiSequence (15 > 10). While the current implementation works, the complexity stems from the nested conditions and could potentially be simplified with a state machine approach if this becomes a maintenance concern.

🧹 Nitpick comments (2)
cmd/root.go (1)

251-259: Smart conditional logic for TTY detection.

The buffering approach with TTY detection is well thought out. However, consider simplifying the conditional logic for better readability.

Consider extracting this logic into a helper function:

+func printStyledAtmosHeader(command *cobra.Command, buf *bytes.Buffer) error {
+	if term.IsTTYSupportForStdout() {
+		return tuiUtils.PrintStyledTextToSpecifiedOutput(buf, "ATMOS")
+	}
+	return tuiUtils.PrintStyledText("ATMOS")
+}
+
 // In the help function:
-		if term.IsTTYSupportForStdout() {
-			err = tuiUtils.PrintStyledTextToSpecifiedOutput(&buf, "ATMOS")
-		} else {
-			err = tuiUtils.PrintStyledText("ATMOS")
-		}
+		err = printStyledAtmosHeader(command, &buf)
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 251-259: cmd/root.go#L251-L259
Added lines #L251 - L259 were not covered by tests

pkg/pager/term_size.go (1)

63-90: Solid content fitting logic with room for enhancement.

The core logic correctly checks both height and width constraints. The approach of measuring actual display width (accounting for tabs and ANSI sequences) is thorough.

Consider whether the height check should be slightly more conservative - you might want to reserve a line or two for shell prompts or status information.

-	// Check height: number of lines should not exceed terminal height
-	if len(lines) > termSize.Height {
+	// Check height: number of lines should not exceed terminal height (reserve 1 line for prompt)
+	if len(lines) >= termSize.Height {
		return false
	}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6462315 and a31575b.

📒 Files selected for processing (5)
  • cmd/root.go (3 hunks)
  • internal/tui/utils/utils.go (2 hunks)
  • pkg/pager/pager.go (2 hunks)
  • pkg/pager/term_size.go (1 hunks)
  • pkg/pager/term_size_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/pager/term_size_test.go (2)
pkg/pager/term_size.go (2)
  • MockTerminalSizer (35-39)
  • ContentFitsTerminal (64-90)
pkg/pager/pager.go (1)
  • New (22-28)
🪛 GitHub Check: codecov/patch
cmd/root.go

[warning] 251-259: cmd/root.go#L251-L259
Added lines #L251 - L259 were not covered by tests


[warning] 266-270: cmd/root.go#L266-L270
Added lines #L266 - L270 were not covered by tests


[warning] 272-272: cmd/root.go#L272
Added line #L272 was not covered by tests

internal/tui/utils/utils.go

[warning] 37-38: internal/tui/utils/utils.go#L37-L38
Added lines #L37 - L38 were not covered by tests

pkg/pager/pager.go

[warning] 31-34: pkg/pager/pager.go#L31-L34
Added lines #L31 - L34 were not covered by tests


[warning] 36-52: pkg/pager/pager.go#L36-L52
Added lines #L36 - L52 were not covered by tests

pkg/pager/term_size.go

[warning] 30-31: pkg/pager/term_size.go#L30-L31
Added lines #L30 - L31 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (17)
internal/tui/utils/utils.go (1)

6-6: Good addition for the new functionality.

The io import supports the new generalized function nicely.

cmd/root.go (2)

4-4: Imports look appropriate for the new functionality.

The new imports support the pager integration and terminal detection features nicely.

Also applies to: 20-20, 24-24


272-272: Consistent formatting with the conditional branch.

Good consistency in adding the newline for both help scenarios.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 272-272: cmd/root.go#L272
Added line #L272 was not covered by tests

pkg/pager/pager.go (4)

4-4: Appropriate imports for the new functionality.

The fmt and term imports support the enhanced pager logic effectively.

Also applies to: 8-8


17-19: Excellent design for testability.

Adding function fields to the struct enables easy mocking and testing. This is a solid architectural choice.


24-26: Clean dependency injection in constructor.

The initialization properly wires up the dependencies for the enhanced functionality.


31-34: Smart early return for non-TTY environments.

The TTY check prevents unnecessary pager activation in non-interactive environments. This is exactly the right behavior.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 31-34: pkg/pager/pager.go#L31-L34
Added lines #L31 - L34 were not covered by tests

pkg/pager/term_size_test.go (7)

1-8: Well-structured test package setup.

The imports and package declaration are clean and appropriate for the testing needs.


9-57: Comprehensive test coverage for terminal size functionality.

The test cases cover the essential scenarios including success, error handling, and edge cases like large dimensions. The mock usage with proper cleanup is excellent.


59-162: Thorough content fitting tests with diverse scenarios.

The test cases effectively cover various content types, terminal sizes, and edge cases. The inclusion of ANSI sequence and tab handling tests is particularly valuable.


164-203: Excellent table-driven tests for display width calculation.

The comprehensive test cases cover all the important scenarios including Unicode, ANSI sequences, control characters, and tab handling. This ensures robust width calculation.


205-267: Solid ANSI sequence handling tests.

The tests thoroughly cover various ANSI escape sequences and edge cases. The separate edge case tests provide additional confidence in the implementation.


269-299: Smart inclusion of performance benchmarks.

The benchmark tests provide valuable performance insights for both individual functions and realistic content scenarios.


301-334: Realistic integration test with practical scenarios.

The integration test covers real-world content types and provides confidence that the entire system works together properly.

pkg/pager/term_size.go (3)

16-20: Well-structured type definition.

The TermSize struct is clean and serves its purpose well for representing terminal dimensions.


22-32: Good use of dependency injection for testability.

The interface pattern here enables clean testing. However, there's a test coverage gap for the real implementation.

The static analysis correctly identifies that lines 30-31 aren't covered by tests. While this is expected since it's a thin wrapper around the system call, consider adding an integration test to ensure the real terminal sizer works in actual terminal environments.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 30-31: pkg/pager/term_size.go#L30-L31
Added lines #L30 - L31 were not covered by tests


92-129: Comprehensive display width calculation with proper ANSI handling.

The implementation correctly handles tabs, carriage returns, and ANSI escape sequences. The tab alignment calculation is mathematically sound, and the Unicode fallback is reasonable.

Comment thread internal/tui/utils/utils.go Resolved
Comment thread cmd/root.go Resolved
Comment thread pkg/pager/pager.go Resolved
Comment thread pkg/pager/pager_test.go Fixed
Comment thread pkg/pager/pager_test.go Fixed
@samtholiya
Sam Tholiya (samtholiya) force-pushed the feature/dev-3299-add-pager-to-help branch from 33dbccc to 6cb2111 Compare June 1, 2025 15:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
pkg/pager/pager_test.go (1)

49-49: Address comment formatting for consistency.

Based on the past review comments, ensure comments end with periods for consistency with your coding standards.

-			// Track whether newTeaProgram was called and capture the model
+			// Track whether newTeaProgram was called and capture the model.

Apply similar changes to other comments throughout the file.

Also applies to: 120-120, 175-175

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a31575b and 6cb2111.

📒 Files selected for processing (1)
  • pkg/pager/pager_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: [localstack] demo-localstack
  • GitHub Check: Acceptance Tests (macos-latest, macos)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Acceptance Tests (ubuntu-latest, linux)
  • GitHub Check: Summary
🔇 Additional comments (8)
pkg/pager/pager_test.go (8)

1-9: Solid foundation with appropriate testing dependencies.

Clean package structure with well-chosen imports for comprehensive testing.


11-45: Excellent table-driven test design covering key scenarios.

The test cases comprehensively cover the decision matrix: TTY support vs content fitting. Good use of descriptive test names and clear expected behaviors.


47-102: Robust mocking approach with thorough verification.

The dependency injection pattern allows for precise control over test conditions. The assertions properly verify both the decision logic and the model initialization details.


104-117: Clean helper model implementation.

Simple and focused test double that serves its purpose well.


143-158: Straightforward error test model.

Simple implementation that serves the testing needs adequately.


160-172: Constructor verification with appropriate type checking.

Good verification that the constructor properly initializes all function dependencies. The type assertion approach works well in the test context.


174-211: Thorough model initialization verification.

Excellent detailed checking of model state and viewport initialization. The assertions ensure the model is properly constructed with expected defaults.


213-254: Comprehensive coverage of non-pager scenarios.

Well-structured test ensuring the pager is correctly bypassed when conditions don't require it. Good use of table-driven approach for different condition combinations.

Comment thread pkg/pager/pager_test.go Resolved
@samtholiya
Sam Tholiya (samtholiya) force-pushed the feature/dev-3299-add-pager-to-help branch from 7ac5b93 to fc96258 Compare June 4, 2025 23:28
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 7, 2025
@settings settings Bot removed the size/l label Jun 12, 2025
@settings settings Bot removed the size/l label Jun 13, 2025
@github-actions github-actions Bot added the size/l Large size PR label Jun 13, 2025
coderabbitai Bot added a commit that referenced this pull request Jun 13, 2025
Docstrings generation was requested by @samtholiya.

* #1276 (comment)

The following files were modified:

* `cmd/root.go`
* `internal/tui/utils/utils.go`
* `pkg/pager/pager.go`
* `pkg/pager/term_size.go`
@samtholiya

Copy link
Copy Markdown
Contributor Author

Ben (@Benbentwo) this is pager for help. We do not require pager flag here... help flag overrides every flag. And that should be by design.

I have added env support but that is all we should do

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/pager/pager.go (1)

23-27: Consider a cleaner constructor pattern.

The type assertion approach works but feels brittle. Consider making the constructor more explicit:

-func NewWithAtmosConfig(enablePager bool) PageCreator {
-	pager := New()
-	pager.(*pageCreator).enablePager = enablePager
-	return pager
-}
+func NewWithAtmosConfig(enablePager bool) PageCreator {
+	return &pageCreator{
+		enablePager:           enablePager,
+		newTeaProgram:         tea.NewProgram,
+		contentFitsTerminal:   ContentFitsTerminal,
+		isTTYSupportForStdout: term.IsTTYSupportForStdout,
+	}
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3575ec and 0500ed4.

📒 Files selected for processing (2)
  • cmd/root.go (3 hunks)
  • pkg/pager/pager.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/root.go
🧰 Additional context used
📓 Path-based instructions (1)
`pkg/*/*.go`: Organize feature implementations in subdirectories under pkg/ with separate files for each feature.

pkg/*/*.go: Organize feature implementations in subdirectories under pkg/ with separate files for each feature.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/atmos-rules.mdc)

List of files the instruction was applied to:

  • pkg/pager/pager.go
🧠 Learnings (2)
📓 Common learnings
Learnt from: RoseSecurity
PR: cloudposse/atmos#848
File: pkg/utils/doc_utils.go:19-22
Timestamp: 2024-12-12T17:13:53.409Z
Learning: In `pkg/utils/doc_utils.go`, the `DisplayDocs` function uses the `PAGER` environment variable, which is intentionally user-configurable to allow users to specify custom pager commands that fit their workflow; adding validation to restrict it is not desired.
Learnt from: samtholiya
PR: cloudposse/atmos#955
File: tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden:0-0
Timestamp: 2025-01-19T15:49:15.593Z
Learning: In future commits, the help text for Atmos CLI commands should be limited to only show component and stack parameters for commands that actually use them. This applies to the example usage section in command help text.
Learnt from: Listener430
PR: cloudposse/atmos#934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
Learnt from: RoseSecurity
PR: cloudposse/atmos#757
File: cmd/docs.go:52-54
Timestamp: 2024-11-01T14:45:32.417Z
Learning: In `cmd/docs.go`, capping the terminal width at 120 columns is considered acceptable and preferred after testing.
pkg/pager/pager.go (13)
Learnt from: RoseSecurity
PR: cloudposse/atmos#848
File: pkg/utils/doc_utils.go:19-22
Timestamp: 2024-12-12T17:13:53.409Z
Learning: In `pkg/utils/doc_utils.go`, the `DisplayDocs` function uses the `PAGER` environment variable, which is intentionally user-configurable to allow users to specify custom pager commands that fit their workflow; adding validation to restrict it is not desired.
Learnt from: samtholiya
PR: cloudposse/atmos#1255
File: cmd/describe_affected.go:122-123
Timestamp: 2025-05-22T19:58:32.988Z
Learning: The "pager" flag is defined as a PersistentFlag at the describe command level in cmd/describe.go, making it available to all subcommands including describeAffectedCmd without needing to redeclare it.
Learnt from: osterman
PR: cloudposse/atmos#740
File: cmd/cmd_utils.go:340-359
Timestamp: 2024-10-23T21:36:40.262Z
Learning: In the Go codebase for Atmos, when reviewing functions like `checkAtmosConfig` in `cmd/cmd_utils.go`, avoid suggesting refactoring to return errors instead of calling `os.Exit` if such changes would significantly increase the scope due to the need to update multiple call sites.
Learnt from: osterman
PR: cloudposse/atmos#808
File: pkg/config/config.go:478-483
Timestamp: 2024-12-02T21:26:32.337Z
Learning: In the 'atmos' project, when reviewing Go code like `pkg/config/config.go`, avoid suggesting file size checks after downloading remote configs if such checks aren't implemented elsewhere in the codebase.
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: All pull requests must pass CI checks, which should run unit tests, integration tests, golangci-lint, and coverage reporting.
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: Before submitting a pull request, ensure all tests pass, code coverage meets targets, golangci-lint issues are fixed, and documentation is updated as needed.
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: Every new feature must include comprehensive unit tests, targeting over 80% code coverage for all packages, and tests should cover both happy paths and error conditions.
Learnt from: osterman
PR: cloudposse/atmos#727
File: internal/exec/terraform.go:114-118
Timestamp: 2024-10-21T17:51:07.087Z
Learning: Use `bubbletea` for confirmation prompts instead of `fmt.Scanln` in the `atmos terraform clean` command.
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: Use interfaces for external dependencies to facilitate mocking, and consider using testify/mock for creating mock implementations.
Learnt from: Listener430
PR: cloudposse/atmos#934
File: internal/exec/template_utils.go:268-271
Timestamp: 2025-01-25T03:49:03.951Z
Learning: The `ProcessTmplWithDatasourcesGomplate` function in `internal/exec/template_utils.go` is used for documentation generation purposes, where simple environment variable handling is acceptable and thread-safety concerns are not critical.
Learnt from: RoseSecurity
PR: cloudposse/atmos#757
File: cmd/docs.go:52-54
Timestamp: 2024-11-01T14:45:32.417Z
Learning: In `cmd/docs.go`, capping the terminal width at 120 columns is considered acceptable and preferred after testing.
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: Use table-driven tests in Go for testing multiple scenarios efficiently.
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: Follow Go's error handling idioms: use meaningful error messages, wrap errors with context using fmt.Errorf("context: %w", err), and consider custom error types for domain-specific errors.
🧬 Code Graph Analysis (1)
pkg/pager/pager.go (2)
pkg/pager/term_size.go (1)
  • ContentFitsTerminal (64-90)
internal/tui/templates/term/term_writer.go (1)
  • IsTTYSupportForStdout (83-87)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Summary
🔇 Additional comments (3)
pkg/pager/pager.go (3)

17-21: Well-designed dependency injection for testability.

The function fields approach enables clean mocking and testing of the pager logic without requiring complex setup or external dependencies.


38-41: Solid early exit strategy.

The combined condition efficiently handles both disabled pager and non-TTY environments by falling back to direct output.


43-60: Smart content-aware paging logic.

The conditional approach properly handles the common case where content fits the terminal without unnecessary pager overhead. The fallback to direct printing maintains good user experience.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 26, 2025
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 26, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
pkg/pager/pager_test.go (1)

120-142: Test logic inconsistency needs clarification.

The test name suggests error handling, but line 141 expects no error. The comment acknowledges that tea.Program.Run() handles model errors internally, making this test's purpose unclear.

🧹 Nitpick comments (1)
pkg/pager/pager_test.go (1)

238-238: Fix misleading comment.

The comment states "Disable pager to test direct printing" but enablePager is set to true.

-				enablePager: true, // Disable pager to test direct printing
+				enablePager: true, // Enable pager but other conditions prevent its use
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 608a05d and a5206bd.

📒 Files selected for processing (1)
  • pkg/pager/pager_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`pkg/*/*.go`: Organize feature implementations in subdirectories under pkg/ with separate files for each feature.

pkg/*/*.go: Organize feature implementations in subdirectories under pkg/ with separate files for each feature.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/atmos-rules.mdc)

List of files the instruction was applied to:

  • pkg/pager/pager_test.go
`pkg/*/*_test.go`: Include comprehensive unit tests for each feature in corresponding *_test.go files.

pkg/*/*_test.go: Include comprehensive unit tests for each feature in corresponding *_test.go files.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/atmos-rules.mdc)

List of files the instruction was applied to:

  • pkg/pager/pager_test.go
🧠 Learnings (2)
📓 Common learnings
Learnt from: RoseSecurity
PR: cloudposse/atmos#848
File: pkg/utils/doc_utils.go:19-22
Timestamp: 2024-12-12T17:13:53.409Z
Learning: In `pkg/utils/doc_utils.go`, the `DisplayDocs` function uses the `PAGER` environment variable, which is intentionally user-configurable to allow users to specify custom pager commands that fit their workflow; adding validation to restrict it is not desired.
Learnt from: samtholiya
PR: cloudposse/atmos#955
File: tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden:0-0
Timestamp: 2025-01-19T15:49:15.593Z
Learning: In future commits, the help text for Atmos CLI commands should be limited to only show component and stack parameters for commands that actually use them. This applies to the example usage section in command help text.
Learnt from: Listener430
PR: cloudposse/atmos#934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
Learnt from: Listener430
PR: cloudposse/atmos#825
File: internal/exec/helmfile_generate_varfile.go:28-31
Timestamp: 2024-12-07T16:16:13.038Z
Learning: In `internal/exec/helmfile_generate_varfile.go`, the `--help` command (`./atmos helmfile generate varfile --help`) works correctly without requiring stack configurations, and the only change needed was to make `ProcessCommandLineArgs` exportable by capitalizing its name.
Learnt from: samtholiya
PR: cloudposse/atmos#1255
File: cmd/describe_affected.go:122-123
Timestamp: 2025-05-22T19:58:32.988Z
Learning: The "pager" flag is defined as a PersistentFlag at the describe command level in cmd/describe.go, making it available to all subcommands including describeAffectedCmd without needing to redeclare it.
Learnt from: RoseSecurity
PR: cloudposse/atmos#757
File: cmd/docs.go:52-54
Timestamp: 2024-11-01T14:45:32.417Z
Learning: In `cmd/docs.go`, capping the terminal width at 120 columns is considered acceptable and preferred after testing.
pkg/pager/pager_test.go (17)
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: Use table-driven tests in Go for testing multiple scenarios efficiently.
Learnt from: RoseSecurity
PR: cloudposse/atmos#848
File: pkg/utils/doc_utils.go:19-22
Timestamp: 2024-12-12T17:13:53.409Z
Learning: In `pkg/utils/doc_utils.go`, the `DisplayDocs` function uses the `PAGER` environment variable, which is intentionally user-configurable to allow users to specify custom pager commands that fit their workflow; adding validation to restrict it is not desired.
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: Every new feature must include comprehensive unit tests, targeting over 80% code coverage for all packages, and tests should cover both happy paths and error conditions.
Learnt from: samtholiya
PR: cloudposse/atmos#1068
File: tests/snapshots/TestCLICommands_atmos_terraform_help.stdout.golden:59-64
Timestamp: 2025-02-18T13:13:11.497Z
Learning: For Atmos CLI help text, angle brackets in command examples and flag descriptions should be escaped using HTML entities (e.g., `&lt;component&gt;`) rather than converted to backticks or other markdown formatting.
Learnt from: osterman
PR: cloudposse/atmos#768
File: internal/exec/vendor_utils.go:496-513
Timestamp: 2024-11-22T12:38:33.132Z
Learning: In the Atmos project, continue to flag path traversal issues in code reviews but acknowledge when they are expected and acceptable in specific cases.
Learnt from: samtholiya
PR: cloudposse/atmos#955
File: tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden:0-0
Timestamp: 2025-01-19T15:49:15.593Z
Learning: In future commits, the help text for Atmos CLI commands should be limited to only show component and stack parameters for commands that actually use them. This applies to the example usage section in command help text.
Learnt from: aknysh
PR: cloudposse/atmos#1185
File: internal/exec/yaml_func_store.go:26-26
Timestamp: 2025-04-04T02:03:23.676Z
Learning: The Atmos codebase currently uses `log.Fatal` for error handling in multiple places. The maintainers are aware this isn't an ideal pattern (should only be used in main() or init() functions) and plan to address it comprehensively in a separate PR. CodeRabbit should not flag these issues or push for immediate changes until that refactoring is complete.
Learnt from: osterman
PR: cloudposse/atmos#740
File: cmd/cmd_utils.go:340-359
Timestamp: 2024-10-23T21:36:40.262Z
Learning: In the Go codebase for Atmos, when reviewing functions like `checkAtmosConfig` in `cmd/cmd_utils.go`, avoid suggesting refactoring to return errors instead of calling `os.Exit` if such changes would significantly increase the scope due to the need to update multiple call sites.
Learnt from: samtholiya
PR: cloudposse/atmos#896
File: cmd/editor_config.go:37-40
Timestamp: 2025-01-07T20:38:09.618Z
Learning: Error handling suggestion for `cmd.Help()` in `cmd/editor_config.go` was deferred as the code is planned for future modifications.
Learnt from: aknysh
PR: cloudposse/atmos#1185
File: internal/exec/yaml_func_store.go:71-72
Timestamp: 2025-04-04T02:03:21.906Z
Learning: The codebase currently uses `log.Fatal` for error handling in library functions, which terminates the program. There is a plan to refactor this approach in a separate PR to improve API design by returning error messages instead of terminating execution.
Learnt from: milldr
PR: cloudposse/atmos#1229
File: internal/exec/workflow_test.go:0-0
Timestamp: 2025-06-02T14:12:02.710Z
Learning: In the atmos codebase, workflow error handling was refactored to use `PrintErrorMarkdown` followed by returning the error instead of `PrintErrorMarkdownAndExit`. This pattern allows proper error testing without the function terminating the process with `os.Exit`, enabling unit tests to assert on error conditions.
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: Follow Go's error handling idioms: use meaningful error messages, wrap errors with context using fmt.Errorf("context: %w", err), and consider custom error types for domain-specific errors.
Learnt from: milldr
PR: cloudposse/atmos#1229
File: internal/exec/workflow_test.go:0-0
Timestamp: 2025-06-02T14:12:02.710Z
Learning: In the atmos codebase, workflow error handling was refactored to use `PrintErrorMarkdown` followed by returning specific error variables (like `ErrWorkflowNoSteps`, `ErrInvalidFromStep`, `ErrInvalidWorkflowStepType`, `ErrWorkflowStepFailed`) instead of `PrintErrorMarkdownAndExit`. This pattern allows proper error testing without the function terminating the process with `os.Exit`, enabling unit tests to assert on error conditions while maintaining excellent user-facing error formatting.
Learnt from: samtholiya
PR: cloudposse/atmos#959
File: cmd/describe_config.go:20-20
Timestamp: 2025-02-03T06:00:11.419Z
Learning: Commands should use `PrintErrorMarkdownAndExit` with empty title and suggestion (`"", err, ""`) for general error handling. Specific titles like "Invalid Usage" or "File Not Found" should only be used for validation or specific error scenarios.
Learnt from: osterman
PR: cloudposse/atmos#715
File: pkg/logger/logger.go:21-32
Timestamp: 2024-10-12T18:38:28.458Z
Learning: In Go code, avoid prefixing struct names with 'I' (e.g., `IError`) as it can be confusing, suggesting an interface. Use descriptive names for structs to improve code clarity.
Learnt from: samtholiya
PR: cloudposse/atmos#1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: The atmos codebase has a custom extension to *testing.T that provides a Chdir method, allowing test functions to call t.Chdir() to change working directories during tests. This is used consistently across test files in the codebase.
Learnt from: CR
PR: cloudposse/atmos#0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-06-23T12:28:41.880Z
Learning: Use interfaces for external dependencies to facilitate mocking, and consider using testify/mock for creating mock implementations.
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Build (macos-latest, macos)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Analyze (go)
  • GitHub Check: Lint (golangci)
  • GitHub Check: Summary
🔇 Additional comments (5)
pkg/pager/pager_test.go (5)

11-103: Solid table-driven test implementation.

The test structure follows Go best practices effectively. The mocking approach for dependencies is clean and the test scenarios cover the key behavioral paths.


105-118: Well-designed test helper.

The simpleTestModel provides a minimal, focused implementation for testing without unnecessary complexity.


161-173: Good constructor validation.

The test properly verifies that New() returns a correctly initialized pageCreator with all required function fields populated.


175-212: Thorough model creation verification.

Nice detailed testing of the model initialization, including viewport state and program options.


214-256: Comprehensive coverage of non-pager scenarios.

Good testing of the conditions where the pager should be bypassed. The test cases cover both TTY and content fitting scenarios appropriately.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 26, 2025
@aknysh Andriy Knysh (aknysh) added no-release Do not create a new release (wait for additional code changes) and removed minor New features that do not break anything labels Jun 29, 2025
@aknysh
Andriy Knysh (aknysh) merged commit a702f6e into main Jun 29, 2025
@aknysh
Andriy Knysh (aknysh) deleted the feature/dev-3299-add-pager-to-help branch June 29, 2025 13:15
Ben (Benbentwo) pushed a commit to Benbentwo/atmos that referenced this pull request Jun 30, 2025
* update help with pager

* [autofix.ci] apply automated fixes

* fix linting issues

* fix test cases

* fix golanglint

* fix golang lint

* fix test cases

* add pager test

* try to fix pager tests

* add pager env support

* pager updated

* pager test

* update test

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Andriy Knysh <[email protected]>
@github-actions

github-actions Bot commented Jul 1, 2025

Copy link
Copy Markdown

These changes were released in v1.182.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-release Do not create a new release (wait for additional code changes) size/l Large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants