Wave/3 ssh is that you - #11
Conversation
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.
There was a problem hiding this comment.
💡 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".
| selectedIdx := -1 | ||
| prompt := &survey.Select{ | ||
| Message: "Select an SSH key:", | ||
| Options: options, | ||
| } | ||
| err = survey.AskOne(prompt, &selectedIdx) | ||
| if err != nil { |
There was a problem hiding this comment.
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 👍 / 👎.
| default: | ||
| // Lines before the first Host entry (globals or comments) | ||
| // For now we ignore them as per previous logic, but satisfied lint "empty branch" | ||
| } |
There was a problem hiding this comment.
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.
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:
internal/utils/ssh_utils.gowith 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.commands.SSHCmdto the root command incmd/root.go.Documentation Updates:
README.mdto include a new section detailing SSH commands, with descriptions for each command related to SSH config, hosts, and keys management.README.mdfor Linux and macOS platforms, and clarified the automatic detection and installation process. [1] [2]README.md.Version Update:
1.2.0to1.3.0ininternal/commands/version.go.