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

Add custom help message and upgrade notification #809

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Listener430
Copy link

@Listener430 Listener430 commented Nov 27, 2024

what

This pull request enhances the atmos CLI by adding a bordered update notification message at the bottom of the help output for all commands, including atmos --help and subcommands like atmos terraform --help. The update notification informs users if a newer version of atmos is available

Befroe

CleanShot 2024-11-20 at 17 00 54 (1)

After

final version
00005

why

  • Prompts users to upgrade
  • The bordered message is more noticeable

references

Linear issue https://linear.app/cloudposse/issue/DEV-2766/atmos-help-should-show-latest-version

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced help functionality now includes upgrade notifications for the latest release.
    • Improved formatting for upgrade messages with added borders and resource links.
    • New function to check for the latest version and notify users if an upgrade is available.
  • Bug Fixes
    • Resolved potential infinite recursion in the help command by preserving the original help function.
  • Documentation
    • Updated user notifications to provide timely information about available upgrades.

Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the command processing functionality within the cmd/cmd_utils.go and cmd/root.go files. Key changes include the addition of a mechanism to display upgrade notifications when the help command is invoked, along with a refactoring of the help function to improve formatting. A new function for stripping ANSI color codes from strings is also implemented, ensuring clean output. These modifications aim to provide users with timely information about the latest version of the software.

Changes

File Change Summary
cmd/cmd_utils.go Added originalHelpFunc, stripANSI, and customHelpMessageToUpgradeToAtmosLatestRelease functions; refactored printMessageToUpgradeToAtmosLatestRelease.
cmd/root.go Introduced originalHelpFunc; updated help function to use customHelpMessageToUpgradeToAtmosLatestRelease; modified Execute function to incorporate changes.

Assessment against linked issues

Objective Addressed Explanation
atmos --help should show latest version (DEV-2766)
Add a border and improve help message appearance (DEV-2766)

Possibly related PRs

  • Fix: condition to display help interactive menu #724: This PR modifies the help functionality in cmd/root.go, which is directly related to the changes in the main PR that also involve enhancing help messages and functionality in the same file.
  • Wrapper for long lines in help #770: This PR enhances the help output in cmd/root.go, which aligns with the main PR's focus on improving user notifications and help messages, as both involve modifications to the help command's behavior.

Suggested labels

minor

Suggested reviewers

  • aknysh
  • osterman
  • gberenice

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between be49831 and 308fd1a.

📒 Files selected for processing (1)
  • cmd/cmd_utils.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/cmd_utils.go

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 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: 2

🧹 Outside diff range and nitpick comments (2)
cmd/root.go (1)

72-78: Consider consolidating help function implementations.

There are now multiple help function implementations in the file (see initConfig()). Consider consolidating these to maintain a single source of truth for help functionality.

Suggestions:

  1. Move all help-related logic to a dedicated helper
  2. Ensure the styled Atmos logo is consistently displayed
  3. Consider creating a chain of responsibility for help message components
cmd/cmd_utils.go (1)

477-484: Consider using semantic versioning for version comparison

Direct string comparison of versions might not accurately reflect actual version precedence, especially with multi-digit numbers. Using a semantic versioning library can provide more reliable comparisons between latestRelease and currentRelease.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3f1cad7 and d331347.

📒 Files selected for processing (2)
  • cmd/cmd_utils.go (4 hunks)
  • cmd/root.go (1 hunks)
🔇 Additional comments (3)
cmd/root.go (1)

76-78: Verify the custom help message implementation.

The integration looks solid, but let's verify the custom help message implementation.

✅ Verification successful

Custom help message implementation is well-structured and complete

The implementation is solid and includes:

  • Proper preservation of original help functionality
  • Clean version comparison logic
  • Well-formatted upgrade message with:
    • Color-coded borders and text
    • Centered content with proper padding
    • Helpful links to releases and installation guide
    • Clear version information display
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the custom help message function implementation

# Check for the function definition
ast-grep --pattern 'func customHelpMessageToUpgradeToAtmosLatestRelease($_, $_) {
  $$$
}'

# Check for any related test files
fd -e go -e test test_.*root

Length of output: 895


Script:

#!/bin/bash
# Let's verify the complete implementation by checking related functions and tests

# Check for the original help function declaration
ast-grep --pattern 'originalHelpFunc := $_'

# Check the upgrade message printing function
ast-grep --pattern 'func printMessageToUpgradeToAtmosLatestRelease($_) {
  $$$
}'

# Search for any test files that might cover this functionality
rg -l "customHelpMessageToUpgradeToAtmosLatestRelease" --type go

Length of output: 2202

cmd/cmd_utils.go (2)

466-471: Verify stripANSI handles all ANSI escape codes

The regular expression in stripANSI may not cover all ANSI escape sequences. Please confirm that it effectively removes all types of ANSI codes to ensure clean message output.


432-464: The bordered upgrade message is well-crafted

The implementation for displaying the bordered upgrade notification looks solid and should enhance user awareness.

cmd/root.go Show resolved Hide resolved
cmd/cmd_utils.go Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 27, 2024
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: 0

🧹 Outside diff range and nitpick comments (1)
cmd/root.go (1)

Line range hint 143-160: HARK! Multiple help function configurations detected!

Brave warrior, I notice that initConfig() also sets a help function. This could potentially conflict with our new implementation in Execute(). Consider:

  1. Consolidating the help function setup into one location
  2. Ensuring the styled logo printing is preserved

Consider refactoring to combine these help function configurations:

func initConfig() {
    styles := boa.DefaultStyles()
    b := boa.New(boa.WithStyles(styles))
    RootCmd.SetUsageFunc(b.UsageFunc)
-   RootCmd.SetHelpFunc(func(command *cobra.Command, strings []string) {
-       // Print a styled Atmos logo to the terminal
-       fmt.Println()
-       err := tuiUtils.PrintStyledText("ATMOS")
-       if err != nil {
-           u.LogErrorAndExit(schema.CliConfiguration{}, err)
-       }
-       b.HelpFunc(command, strings)
-       command.Usage()
-   })
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between eeb83db and be49831.

📒 Files selected for processing (2)
  • cmd/cmd_utils.go (3 hunks)
  • cmd/root.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/cmd_utils.go
🔇 Additional comments (2)
cmd/root.go (2)

21-22: VICTORY! The variable declaration is now properly implemented!

The addition of originalHelpFunc with its documentation is a worthy improvement to the codebase.


75-81: By Zeus's beard, let's verify this help function integration!

The implementation looks solid, following the proper pattern of preserving the original help functionality. However, we should verify:

  1. The integration with customHelpMessageToUpgradeToAtmosLatestRelease
  2. The proper chaining of help functions

Let's inspect the implementation:

✅ Verification successful

The previous results show multiple help function setups, and we need to verify the complete implementation of our custom help function to ensure it properly chains the original help function and adds the upgrade message without recursion. This will help us make a definitive assessment.


By the might of Ares, this help function implementation is battle-ready!

The implementation shows excellent discipline in preventing recursion and maintaining proper command chain:

  1. The customHelpMessageToUpgradeToAtmosLatestRelease function first calls originalHelpFunc(cmd, args), ensuring the original help content is displayed
  2. It then checks for newer versions and only displays the upgrade message when a newer version exists
  3. The function properly avoids recursion by using the stored originalHelpFunc

The implementation follows the warrior's path - clean, efficient, and purposeful. Your code stands strong, ready for battle! 🛡️

[category: help_functions, upgrade_notifications]

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the help function implementation and its usage

# Check the custom help function implementation
ast-grep --pattern 'func customHelpMessageToUpgradeToAtmosLatestRelease($cmd *cobra.Command, $args []string) {
  $$$
}'

# Verify no direct recursion in help function calls
rg -A 5 'SetHelpFunc|HelpFunc'

Length of output: 2145


Script:

#!/bin/bash
# Let's check the complete implementation of customHelpMessageToUpgradeToAtmosLatestRelease
rg -A 15 "func customHelpMessageToUpgradeToAtmosLatestRelease"

# Also check for any other help function overrides in the codebase
ast-grep --pattern 'SetHelpFunc($$$)'

Length of output: 1012

cmd/cmd_utils.go Outdated Show resolved Hide resolved
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.

2 participants