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

Merged
merged 5 commits into from
Dec 5, 2024

Conversation

Listener430
Copy link
Collaborator

@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

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.

@Listener430 Listener430 requested review from a team as code owners November 27, 2024 14:25
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. The modifications focus on providing users with timely information about the latest version of the software while maintaining existing command processing logic.

Changes

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

Assessment against linked issues

Objective Addressed Explanation
Emit a warning for out-of-date version (263) The implementation checks for the latest version but does not emit a warning to STDERR as specified.
atmos --help should show latest version (DEV-2766)
Add a border and improve help message appearance (DEV-2766)

Possibly related PRs

Suggested reviewers

  • osterman
  • gberenice

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
coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 28, 2024
@Listener430
Copy link
Collaborator Author

@aknysh hi, would appreciate if you take a look.

@osterman
Copy link
Member

osterman commented Dec 4, 2024

@Listener430 we should print the upgrade message on any --help command.

image

@osterman osterman added the minor New features that do not break anything label Dec 4, 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/cmd_utils.go (1)

428-458: Consider extracting color codes into constants.

The implementation looks good and follows the suggested lipgloss styling. However, the color codes could be made more maintainable.

Consider extracting the color codes into named constants at the package level:

+const (
+    colorSubdued  = "8"   // For version
+    colorHighlight = "10" // For latest version and border
+    colorLink     = "14"  // For URLs
+)

 func printMessageToUpgradeToAtmosLatestRelease(latestVersion string) {
     // Define colors
-    c1 := lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
-    c2 := lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
-    c3 := lipgloss.NewStyle().Foreground(lipgloss.Color("14"))
+    c1 := lipgloss.NewStyle().Foreground(lipgloss.Color(colorSubdued))
+    c2 := lipgloss.NewStyle().Foreground(lipgloss.Color(colorHighlight))
+    c3 := lipgloss.NewStyle().Foreground(lipgloss.Color(colorLink))
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

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

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

11-11: LGTM! Required imports are in place.

The new imports for lipgloss and version packages are correctly added and necessary for the upgrade notification feature.

Also applies to: 20-20


460-471: Verify help function override for subcommands.

Let's ensure the custom help function is properly set for all subcommands.

✅ Verification successful

Help function is properly configured for all commands

The custom help function is correctly set at the root level and will propagate to all subcommands. The implementation in cmd/root.go shows:

  • The original help function is properly preserved to avoid recursion
  • SetHelpFunc(customHelpMessageToUpgradeToAtmosLatestRelease) is called on the root command
  • No subcommands override this help function
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if any commands have their own help function that might override our custom one

# Search for SetHelpFunc or SetHelpCommand in the codebase
rg -l "SetHelpFunc|SetHelpCommand" --type go

# Search for help function declarations
ast-grep --pattern 'func $_(cmd *cobra.Command, args []string) {
  $$$
  cmd.Help()
  $$$
}'

Length of output: 153


Script:

#!/bin/bash
# Let's check the content of root.go to see how the help function is set
cat cmd/root.go

# Also check for any other potential help-related functions in the codebase
rg "func.*help" -i --type go

Length of output: 6978


460-471: ⚠️ Potential issue

Add nil check for originalHelpFunc.

The function correctly implements the version check, but there's a potential nil pointer dereference.

Add a nil check before calling originalHelpFunc:

 func customHelpMessageToUpgradeToAtmosLatestRelease(cmd *cobra.Command, args []string) {
+    if originalHelpFunc == nil {
+        cmd.Help()
+        return
+    }
     originalHelpFunc(cmd, args)
     // Check for the latest Atmos release on GitHub
     latestReleaseTag, err := u.GetLatestGitHubRepoRelease("cloudposse", "atmos")

Likely invalid or redundant comment.

@Listener430
Copy link
Collaborator Author

@osterman thanks, sure, here is the new design with the lipgloss
Updated_screenshot_lipgloss
Wrt the help messages, my bad, have overlooked terraform and helm files. Will place the border function call into internal\exec\help.go where all the exceptions go. Let me know if threre are any reservations at your side.

@osterman
Copy link
Member

osterman commented Dec 4, 2024

We've decided that this can be done in a separate PR:

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 (1)
cmd/cmd_utils.go (1)

434-464: Consider defining color constants and adding error handling.

The implementation looks good, but could be enhanced for maintainability and robustness.

Consider these improvements:

+ // Color constants for consistent styling
+ const (
+    versionColor = "8"
+    newVersionColor = "10"
+    linkColor = "14"
+ )

 func printMessageToUpgradeToAtmosLatestRelease(latestVersion string) {
     // Define colors
-    c1 := lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
-    c2 := lipgloss.NewStyle().Foreground(lipgloss.Color("10"))
-    c3 := lipgloss.NewStyle().Foreground(lipgloss.Color("14"))
+    c1 := lipgloss.NewStyle().Foreground(lipgloss.Color(versionColor))
+    c2 := lipgloss.NewStyle().Foreground(lipgloss.Color(newVersionColor))
+    c3 := lipgloss.NewStyle().Foreground(lipgloss.Color(linkColor))
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9cd2676 and 49a3ac4.

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

11-11: LGTM! Clean import additions.

The new imports for lipgloss styling and version comparison are well-organized and necessary for the new functionality.

Also applies to: 20-20


468-468: ⚠️ Potential issue

Ensure originalHelpFunc is initialized.

The function uses originalHelpFunc which could be nil. This is a critical issue that was previously identified.

Add a guard clause:

 func customHelpMessageToUpgradeToAtmosLatestRelease(cmd *cobra.Command, args []string) {
+    if originalHelpFunc == nil {
+        cmd.Help()
+        return
+    }
     originalHelpFunc(cmd, args)

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

thanks @Listener430

@aknysh aknysh merged commit 31d7c5e into cloudposse:main Dec 5, 2024
27 checks passed
Copy link

github-actions bot commented Dec 5, 2024

These changes were released in v1.115.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
Status: Done
Development

Successfully merging this pull request may close these issues.

Atmos should warn if not on latest version
3 participants