Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pagination and searching to atmos docs command #848

Merged
merged 4 commits into from
Dec 14, 2024

Conversation

RoseSecurity
Copy link
Contributor

@RoseSecurity RoseSecurity commented Dec 12, 2024

what

atmos_docs

  • Add pagination helper function to utils
  • Add pagination setting to Doc struct
  • Update website documentation to incorporate new CLI settings

why

  • Enhance the user experience by making it possible to paginate and search component documentation

references

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced pagination options for displaying component documentation.
    • Added a new docs section in the atmos.yaml configuration file for enhanced documentation settings.
  • Bug Fixes

    • Improved error handling in the documentation display process.
  • Documentation

    • Updated documentation for the atmos.yaml configuration file, including detailed descriptions of new settings and merge strategies.
  • Chores

    • Minor formatting adjustments made for improved readability.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the documentation display within the Atmos CLI. Key changes include the implementation of a new DisplayDocs function for improved documentation output with pagination support. The CliConfiguration schema is updated to include a Pagination field, and the documentation for the atmos.yaml configuration file is enhanced to clarify new settings. Error handling is also strengthened in the documentation display process, ensuring better management of potential issues.

Changes

File Change Summary
cmd/docs.go Replaced fmt.Println(componentDocs) with u.DisplayDocs(componentDocs, cliConfig.Settings.Docs.Pagination); added error handling for DisplayDocs.
pkg/schema/schema.go Added new field Pagination bool to Docs struct; reformatted MaxWidth field declaration.
pkg/utils/doc_utils.go Introduced DisplayDocs function to display documentation with optional pager support.
website/docs/cli/configuration/configuration.mdx Added docs section under settings in atmos.yaml with max-width and pagination options; clarified list_merge_strategy.

Possibly related PRs

Suggested labels

minor

Suggested reviewers

  • Gowiem
  • aknysh
  • osterman
  • nitrocode

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Experiment)
  • @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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
pkg/utils/doc_utils.go (1)

29-32: Consider adding timeout for pager execution

The pager execution could potentially hang indefinitely. Consider adding a context with timeout.

+import "context"

-cmd := exec.Command(args[0], args[1:]...)
+ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+defer cancel()
+cmd := exec.CommandContext(ctx, args[0], args[1:]...)
website/docs/cli/configuration/configuration.mdx (2)

154-160: Documentation looks good, but consider adding environment variable support.

The new docs configuration section is well-documented with clear examples. However, it would be beneficial to support environment variables for these settings, similar to other configuration options.

Consider adding support for:

  • ATMOS_SETTINGS_DOCS_MAX_WIDTH
  • ATMOS_SETTINGS_DOCS_PAGINATION

Line range hint 1-1000: Add environment variables for the new docs settings to the table.

The environment variables table should be updated to include the new docs settings for completeness.

Add these entries to the environment variables table:

 | ATMOS_SETTINGS_LIST_MERGE_STRATEGY                    | settings.list_merge_strategy                    | Specifies how lists are merged in Atmos stack manifests. The following strategies are supported: `replace`, `append`, `merge`                                                                                                |
+| ATMOS_SETTINGS_DOCS_MAX_WIDTH                         | settings.docs.max-width                         | The maximum width for displaying component documentation in the terminal                                                                                                                                                    |
+| ATMOS_SETTINGS_DOCS_PAGINATION                        | settings.docs.pagination                        | When enabled, displays component documentation in a pager instead of directly in the terminal                                                                                                                               |
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 22c9b28 and ee3f3b0.

📒 Files selected for processing (4)
  • cmd/docs.go (1 hunks)
  • pkg/schema/schema.go (1 hunks)
  • pkg/utils/doc_utils.go (1 hunks)
  • website/docs/cli/configuration/configuration.mdx (2 hunks)
🔇 Additional comments (3)
cmd/docs.go (1)

100-102: LGTM! Error handling is properly implemented

The code correctly handles errors from DisplayDocs and uses the pagination setting from the CLI configuration.

pkg/schema/schema.go (1)

37-38: LGTM! Schema changes are well-structured

The new Pagination field is properly defined with consistent tags and appropriate type.

website/docs/cli/configuration/configuration.mdx (1)

181-195: LGTM! Clear and well-structured documentation.

The documentation for the docs settings is comprehensive and follows the established format. The description list (<dl>) structure maintains consistency with the rest of the document.

pkg/utils/doc_utils.go Show resolved Hide resolved
@osterman
Copy link
Member

@RoseSecurity thanks for the PR!

We have a task interally to implement the same pager and search as in glow (using the underlying go modules).

Glow UI Demo

I suppose we can take this PR as a short-term workaround. I think the UI glow beats less.

I guess this current implementation would work if PAGER=glow, but we're trying to avoid requiring a lot of other utilities getting installed.

@osterman
Copy link
Member

Or maybe we can support both, a custom pager, and a nice built-in one.

@RoseSecurity
Copy link
Contributor Author

RoseSecurity commented Dec 12, 2024

Feel free to approve this, or we can close it if needed (my feelings won't be hurt)! I added an initial function to utils that can serve as scaffolding for future enhancements. Glow uses a similar implementation for basic functionality, which we could expand upon:

	if pager || cmd.Flags().Changed("pager") {
		pagerCmd := os.Getenv("PAGER")
		if pagerCmd == "" {
			pagerCmd = "less -r"
		}

		pa := strings.Split(pagerCmd, " ")
		c := exec.Command(pa[0], pa[1:]...) // nolint:gosec
		c.Stdin = strings.NewReader(out)
		c.Stdout = os.Stdout
		return c.Run()

@osterman
Copy link
Member

@aknysh let's merge this after you're 👍 review

@osterman osterman requested review from aknysh and removed request for johncblandii and jamengual December 12, 2024 21:04
@aknysh aknysh added the minor New features that do not break anything label Dec 14, 2024
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thank you @RoseSecurity

@aknysh aknysh merged commit 5681e54 into main Dec 14, 2024
29 checks passed
@aknysh aknysh deleted the add-pagination-and-search-to-docs-cmd branch December 14, 2024 20:42
Copy link

These changes were released in v1.124.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants