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/ssh config #37

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

Feat/ssh config #37

wants to merge 3 commits into from

Conversation

FilippoTrotter
Copy link
Collaborator

@FilippoTrotter FilippoTrotter commented Jul 11, 2024

Add possibility to specify port for ssh connection and allows to use ssh_config

Summary by CodeRabbit

  • New Features

    • Added a flag to specify the server port, allowing users to override the default port.
  • Improvements

    • Enhanced file selection interface to better display help messages and selection details.
    • Implemented dynamic window resizing for a more responsive UI.
  • Bug Fixes

    • Adjusted tests to align with new function parameters, ensuring better test coverage and reliability.
  • Dependencies

    • Added github.com/kevinburke/ssh_config v1.2.0 for improved SSH configuration handling.

Copy link
Contributor

coderabbitai bot commented Jul 11, 2024

Walkthrough

Walkthrough

The recent updates introduce a dynamic port configuration for the server, allowing users to specify the port via a command-line flag. This enhancement affects the server initialization, the command execution flow, and the TUI (Text User Interface) module to support window resizing. The changes also include updating tests and the integration of the ssh_config library to manage SSH configurations dynamically.

Changes

File Change Summary
cmd/root.go Added port variable and corresponding flag to rootCmd.PersistentFlags() for specifying server port.
cmd/server.go Integrated ssh_config, modified Run to use serverPort, and restructured executeRemoteCommand.
go.mod Added github.com/kevinburke/ssh_config v1.2.0 to dependencies.
utils/server/server.go StartServer function now accepts a port parameter for dynamic port configuration.
utils/tui/model_test.go Updated tests to include an additional parameter in InitialModel function call.
utils/tui/modelutils/file.go Modified FilesSelector struct and InitialModel function to include and handle windowWidth.
utils/tui/modelutils/file_test.go Updated tests to match the new InitialModel function signature and added necessary assertions.

Sequence Diagrams

New Server Initialization Flow

sequenceDiagram
    participant User
    participant RootCmd
    participant ServerCmd
    participant StartServer

    User->>RootCmd: Execute command with --port flag
    RootCmd->>ServerCmd: Pass port flag value
    ServerCmd->>StartServer: Call with serverPort parameter
    StartServer->>Server: Start server on specified port
Loading

Updated Command Execution Flow

sequenceDiagram
    participant User
    participant ServerCmd
    participant ssh_config
    participant executeRemoteCommand
    participant RemoteServer

    User->>ServerCmd: Execute remote command
    ServerCmd->>ssh_config: Obtain sshPort
    ServerCmd->>executeRemoteCommand: Call with required parameters
    executeRemoteCommand->>RemoteServer: Execute command on remote server
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@FilippoTrotter FilippoTrotter linked an issue Jul 11, 2024 that may be closed by this pull request
2 tasks
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: 4

Outside diff range, codebase verification and nitpick comments (2)
cmd/server.go (1)

30-33: Clarify the description for the port flag.

The description for the port flag is a bit unclear. Simplify and clarify it for better understanding.

- serverCmd.PersistentFlags().StringVarP(&serverPort, "port", "p", "2222", "Specify the port number to use for connecting to the server. This option allows you to override the default port, which 2222.")
+ serverCmd.PersistentFlags().StringVarP(&serverPort, "port", "p", "2222", "Specify the port number for the server (default: 2222).")
utils/tui/modelutils/file.go (1)

Line range hint 26-52:
Handle errors in InitialModel more gracefully.

The InitialModel function should handle errors more gracefully and provide meaningful messages.

func InitialModel(currentDir string, windowHeight int, windowWidth int) FilesSelector {
	var filesAndDir []string
	selectedFilesAndDir := make(map[int]bool)

	entries, err := os.ReadDir(currentDir)
	if err != nil {
		return FilesSelector{Error: fmt.Errorf("error reading directory '%s': %w", currentDir, err)}
	}

	for _, entry := range entries {
		entryPath, err := GetPathOfEntry(entry, currentDir)
		if err != nil {
			return FilesSelector{Error: fmt.Errorf("error getting path of entry '%s': %w", entry.Name(), err)}
		}
		filesAndDir = append(filesAndDir, entryPath)
	}

	for i := 0; i < len(filesAndDir); i++ {
		selectedFilesAndDir[i] = false
	}

	return FilesSelector{
		CurrentDir:          currentDir,
		FilesAndDir:         filesAndDir,
		SelectedFilesAndDir: selectedFilesAndDir,
		WindowHeight:        windowHeight,
		WindowWidth:         windowWidth,
	}
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4088ab0 and 7800b7b.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (7)
  • cmd/root.go (3 hunks)
  • cmd/server.go (2 hunks)
  • go.mod (1 hunks)
  • utils/server/server.go (1 hunks)
  • utils/tui/model_test.go (7 hunks)
  • utils/tui/modelutils/file.go (5 hunks)
  • utils/tui/modelutils/file_test.go (14 hunks)
Files skipped from review due to trivial changes (1)
  • go.mod
Additional context used
golangci-lint
utils/server/server.go

[warning] 34-34: exported: exported function StartServer should have comment or be unexported

(revive)

utils/tui/modelutils/file.go

123-123: (*FilesSelector).doResize - result 0 (github.com/charmbracelet/bubbletea.Cmd) is always nil

(unparam)

Additional comments not posted (12)
utils/server/server.go (1)

40-47: Ensure error handling for window dimensions.

The InitialModel function initializes FilesSelector with window dimensions. Ensure that these dimensions are valid and handle any potential errors.

Is there a guarantee that pty.Window.Height and pty.Window.Width will always have valid values? If not, consider adding error handling for invalid dimensions.

cmd/server.go (3)

16-16: Verify the new dependency.

The github.com/kevinburke/ssh_config package has been added. Ensure this dependency is necessary and correctly integrated.

Confirm that ssh_config is the best choice for handling SSH configuration. If there are alternatives, consider their pros and cons.


27-27: Ensure serverPort is validated.

The serverPort variable should be validated to ensure it contains a valid port number before passing it to StartServer.

Ensure that serverPort is always a valid port number. Consider adding validation logic if it is not already handled.


39-55: Ensure robust handling of remotePath formats.

The executeRemoteCommand function handles different remotePath formats. Ensure all edge cases are covered and errors are handled gracefully.

Confirm that all possible formats of remotePath are handled. Consider adding more test cases to cover edge cases.

utils/tui/modelutils/file.go (1)

23-23: Ensure WindowWidth is initialized correctly.

The WindowWidth field has been added to the FilesSelector struct. Ensure it is always initialized correctly.

Confirm that WindowWidth is always set to a valid value during initialization.

utils/tui/modelutils/file_test.go (1)

141-141: Ensure comprehensive test coverage.

Ensure that the test cases cover all edge cases for the InitialModel function, including invalid directory paths and edge cases for window dimensions.

Consider adding more test cases to cover edge cases for InitialModel.

cmd/root.go (2)

24-24: LGTM!

The port variable is correctly declared to allow port configuration.


66-66: LGTM!

The port flag is correctly added to rootCmd.PersistentFlags() to allow users to specify the port number for SSH connections.

utils/tui/model_test.go (4)

16-16: LGTM!

The InitialModel function call is correctly updated to include the windowWidth parameter in the Init test case.


35-35: LGTM!

The InitialModel function calls are correctly updated to include the windowWidth parameter in the Update test cases.

Also applies to: 54-54, 72-72


159-159: LGTM!

The InitialModel function calls are correctly updated to include the windowWidth parameter in the ModeSelection test cases.

Also applies to: 177-177


427-427: LGTM!

The InitialModel function call is correctly updated to include the windowWidth parameter in the View test case.

utils/server/server.go Show resolved Hide resolved
utils/tui/modelutils/file.go Show resolved Hide resolved
utils/tui/modelutils/file.go Show resolved Hide resolved
utils/tui/modelutils/file_test.go 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.

User interaction server
1 participant