Skip to content

Wave/3 ssh is that you - #11

Open
YoungMayor wants to merge 3 commits into
mainfrom
wave/3-ssh-is-that-you
Open

Wave/3 ssh is that you#11
YoungMayor wants to merge 3 commits into
mainfrom
wave/3-ssh-is-that-you

Conversation

@YoungMayor

Copy link
Copy Markdown
Contributor

This pull request adds comprehensive SSH management functionality to the CLI, including commands for managing SSH config entries, known hosts, and SSH keys. It also updates documentation and increments the version number. The most important changes are grouped below:

SSH Management Feature Implementation:

  • Added internal/utils/ssh_utils.go with utility functions for parsing, editing, and managing SSH config entries, known hosts, and SSH keys. This includes functions for listing, adding, removing, and generating keys, as well as manipulating SSH config and known_hosts files.
  • Registered the new SSH command group by adding commands.SSHCmd to the root command in cmd/root.go.

Documentation Updates:

  • Expanded the README.md to include a new section detailing SSH commands, with descriptions for each command related to SSH config, hosts, and keys management.
  • Updated installation instructions in README.md for Linux and macOS platforms, and clarified the automatic detection and installation process. [1] [2]
  • Added SSH commands to the feature listing in the CLI command summary table in README.md.

Version Update:

  • Bumped the CLI version from 1.2.0 to 1.3.0 in internal/commands/version.go.

Introduce a new SSH CLI surface and supporting utilities.

- Add internal/commands/ssh.go: implements `mayrlabs ssh` with subcommands for config (list/add/edit/remove/export/import/path/connect/validate), hosts (list/remove), keys (list/create/manipulate) and direct connect functionality. Uses interactive prompts and invokes ssh/ssh-keygen where appropriate.
- Add internal/utils/ssh_utils.go: helpers for reading/writing ~/.ssh/config, adding/removing entries, known_hosts handling, listing/generating SSH keys and removing known hosts.
- Register SSHCmd in cmd/root.go so the command is available.
- Bump Version from 1.2.0 to 1.3.0 in internal/commands/version.go.
- Update README.md to document the new SSH commands and add minor formatting tweaks.

Notes: New code depends on interactive libraries (survey, clipboard) and invokes system ssh/ssh-keygen; config parsing/writing is a simplified implementation.
Add interactive survey-based menus for ssh, config, keys and hosts (run when commands invoked without args) and wire RunE handlers to launch them. Replace deprecated ioutil uses with os equivalents (ReadFile/WriteFile/ReadDir), add stricter error checks for survey prompts, file/IO operations, exec runs, os.Rename/os.Remove, and tabwriter writes. Improve SSH config parsing/writing with switch-style parsing, safer deferred closes, and propagate write errors; ensure commands handle empty lists gracefully. Also update .gitignore to include mayrlabs-go.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d186965508

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/commands/ssh.go
Comment on lines +795 to +801
selectedIdx := -1
prompt := &survey.Select{
Message: "Select an SSH key:",
Options: options,
}
err = survey.AskOne(prompt, &selectedIdx)
if err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Fix SSH key selection to return a key, not an index

The survey.Select prompt returns the selected option string, but the code binds it to an int (selectedIdx) and then indexes keys[selectedIdx]. In practice this causes the prompt to fail with a type error or leaves selectedIdx at -1, leading to a panic when indexing. This breaks the SSH key management flow whenever a user picks a key; use a string selection or survey.WithValidator + survey.Select that returns the option string and map it back to a key.

Useful? React with 👍 / 👎.

Comment on lines +81 to +84
default:
// Lines before the first Host entry (globals or comments)
// For now we ignore them as per previous logic, but satisfied lint "empty branch"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve global SSH config lines when editing/removing

The parser drops any lines before the first Host entry (e.g., Include, Host * defaults, comments). When a user edits or removes a host, WriteSSHConfig rewrites the file from the parsed entries, so these global directives are silently lost. This can break existing SSH behavior after any edit/remove. Consider storing and re-emitting pre‑Host lines (and other non‑host blocks) so rewrites are lossless.

Useful? React with 👍 / 👎.

Improve the SSH CLI UX by adding interactive helpers and advanced auth options. Introduces promptIdentityFile and promptAuthOptions for selecting identity files (including listing existing keys or custom path) and configuring PreferredAuthentications / Pubkey/Password/KeyboardInteractive options. Extends SSHConfigEntry with new auth fields and updates ParseSSHConfig, WriteSSHConfig and AddSSHConfigEntry to persist those options. Replaces several confirm prompts with utils.ConfirmWithPIN, adds safer export handling (overwrite/rename/timestamp/cancel) and timestamping, enables multi-select removal for known_hosts, and enhances key creation (pre-checks for existing files and post-generation actions: copy/show/install). Adds minor refactors to streamline add/edit/import/export/connect/remove flows and imports time where needed.
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.

1 participant