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 support for disabling custom terraform shell prompt #786

Merged
merged 5 commits into from
Nov 16, 2024
Merged

Conversation

pkbhowmick
Copy link
Collaborator

@pkbhowmick pkbhowmick commented Nov 15, 2024

what

why

Working demo

With custom prompt:

Screenshot 2024-11-16 at 11 20 14 PM

Without custom prompt:

image

Closes #779 (disable new prompt by default until we make it work better with geodesic)

references

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a configurable shell prompt for Terraform commands, allowing users to customize their command-line interface.
    • Added a new ShellConfig type to support the new shell prompt configuration.
  • Bug Fixes

    • Improved flexibility in shell prompt settings by allowing dynamic configuration based on user-defined CLI settings.

@pkbhowmick pkbhowmick marked this pull request as ready for review November 16, 2024 06:34
@pkbhowmick pkbhowmick requested review from a team as code owners November 16, 2024 06:34
Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>
Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>
Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>
Copy link
Contributor

coderabbitai bot commented Nov 16, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications to the shell prompt configuration in the Atmos CLI. Specifically, the execTerraformShellCommand function now sets the shell prompt based on a configurable value rather than a hardcoded string. Additionally, a new ShellConfig type has been introduced in the schema to facilitate this configuration, allowing for a more flexible approach to defining the shell prompt within the CLI environment.

Changes

File Change Summary
internal/exec/shell_utils.go Modified execTerraformShellCommand to set shell prompt based on cliConfig.Components.Terraform.Shell.Prompt.
pkg/schema/schema.go Introduced ShellConfig type and added Shell field to Terraform struct for prompt configuration.

Assessment against linked issues

Objective Addressed Explanation
Maintain shell prompt as expected in terraform shell (779, DEV-2743)

Possibly related PRs

Suggested labels

minor, patch

Suggested reviewers

  • osterman
  • aknysh

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e4ce923 and e5c9c69.

📒 Files selected for processing (1)
  • internal/exec/shell_utils.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/exec/shell_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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
pkg/schema/schema.go (1)

79-81: Consider adding field documentation.

The ShellConfig struct is well-designed with a focused responsibility. To maintain consistency with Go best practices, consider adding a documentation comment to describe the purpose of the Prompt field.

 type ShellConfig struct {
+    // Prompt defines the custom shell prompt string. If empty, the default prompt is used.
     Prompt string `yaml:"prompt" json:"prompt" mapstructure:"prompt"`
 }
🛑 Comments failed to post (1)
internal/exec/shell_utils.go (1)

158-160: 💡 Codebase verification

⚠️ Potential issue

Shell prompt environment variable needs PS1 prefix

Greetings, fellow code warrior! Our reconnaissance has revealed that the shell prompt is indeed being set without the crucial PS1= prefix. The configuration struct shows it's a raw string value, and there are no existing PS1 environment variable settings in the codebase.

Let's fortify this code:

 if cliConfig.Components.Terraform.Shell.Prompt != "" {
-    componentEnvList = append(componentEnvList, cliConfig.Components.Terraform.Shell.Prompt)
+    componentEnvList = append(componentEnvList, fmt.Sprintf("PS1=%s", cliConfig.Components.Terraform.Shell.Prompt))
 }

This change:

  • Properly formats the shell prompt as an environment variable
  • Maintains compatibility with standard shell behavior
  • Ensures the prompt will be correctly interpreted by the shell
🔗 Analysis chain

Ensure proper shell prompt environment variable format

Greetings, warrior! While the implementation aligns well with making the prompt optional, we should ensure the prompt is properly formatted when added to the environment variables.

Consider this battle-tested approach:

 if cliConfig.Components.Terraform.Shell.Prompt != "" {
-    componentEnvList = append(componentEnvList, cliConfig.Components.Terraform.Shell.Prompt)
+    componentEnvList = append(componentEnvList, fmt.Sprintf("PS1=%s", cliConfig.Components.Terraform.Shell.Prompt))
 }

This ensures:

  1. The prompt is properly prefixed with PS1=
  2. Consistent behavior across different shells

Let's verify the shell prompt handling in other parts of the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other shell prompt configurations
rg -l 'PS1=' 

# Search for any shell environment variable settings
ast-grep --pattern 'componentEnvList = append($_, $_)'

Length of output: 1003


Script:

#!/bin/bash
# Let's check the configuration struct to understand how the prompt is defined
rg -A 5 "type.*Shell.*struct" 

# Also check for any documentation about the shell prompt format
rg -i "shell.*prompt|prompt.*shell" 

Length of output: 722

@osterman
Copy link
Member

@pkbhowmick please update docs on atmos shell

@osterman
Copy link
Member

@pkbhowmick please post screenshots with it enabled and disabled

@osterman
Copy link
Member

@coderabbitai full review

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)
internal/exec/shell_utils.go (1)

159-162: Document the default prompt behavior.

Since this change introduces configurable prompts, we should ensure the behavior is well-documented. Consider adding code comments explaining:

  • The default behavior when no prompt is specified
  • The format expectations for custom prompts
  • Any limitations or security considerations
+// hasCustomShellPrompt determines if a user-defined shell prompt should be used.
+// When no prompt is specified, the default Terraform shell prompt is maintained.
+// Custom prompts should avoid shell metacharacters for security.
 hasCustomShellPrompt := cliConfig.Components.Terraform.Shell.Prompt != ""
pkg/schema/schema.go (1)

79-81: LGTM! Well-structured ShellConfig type.

The new ShellConfig type is cleanly defined with appropriate struct tags. The Prompt field provides a clear configuration point for customizing the shell prompt.

Consider adding validation for the prompt string in the future if there are any format requirements or restrictions that should be enforced.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 81f6db2 and 8d06b14.

📒 Files selected for processing (2)
  • internal/exec/shell_utils.go (1 hunks)
  • pkg/schema/schema.go (1 hunks)
🔇 Additional comments (1)
pkg/schema/schema.go (1)

69-77: LGTM! Clean addition of the Shell configuration field.

The reformatting and addition of the Shell field to the Terraform struct follows consistent patterns with other fields. The struct tags are properly defined for YAML, JSON, and mapstructure serialization.

internal/exec/shell_utils.go Outdated Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 16, 2024
@pkbhowmick
Copy link
Collaborator Author

pkbhowmick commented Nov 16, 2024

@pkbhowmick please update docs on atmos shell

Hi @osterman, could you please give me a pointer in the doc where to update? Should I add a new section for it?

@osterman
Copy link
Member

Without the prompt, we should use the login shell like before. Also show screenshots using atmos templates.

Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>
@pkbhowmick
Copy link
Collaborator Author

pkbhowmick commented Nov 16, 2024

Without the prompt, we should use the login shell like before. Also show screenshots using atmos templates.

Hi @osterman templating is bit tricky here as user can put anything on config. But for now code can handle any combination of stack and component name

With template:

image

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 16, 2024
@osterman
Copy link
Member

But for now code can handle any combination of stact and component name

Great, I wanted to confirm this worked. Please add as an example to the docs.

@osterman
Copy link
Member

Share an updated screenshot of the login shell working.

Signed-off-by: Pulak Kanti Bhowmick <pkbhowmick007@gmail.com>
@pkbhowmick
Copy link
Collaborator Author

Share an updated screenshot of the login shell working.

Here is the login shell example:

image

@aknysh aknysh added the minor New features that do not break anything label Nov 16, 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.

thanks @pkbhowmick

@aknysh aknysh merged commit f909493 into main Nov 16, 2024
30 checks passed
@aknysh aknysh deleted the pulak/DEV-2743 branch November 16, 2024 20:37
Copy link

These changes were released in v1.107.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 terraform shell Prompt Regression
3 participants