-
Notifications
You must be signed in to change notification settings - Fork 2
feat(cmd)!: Add add sub command to replace previous --add flag
#11
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to this project will be documented in this file. | ||
|
|
||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
|
||
| ## [v0.2.0] | ||
|
|
||
| ### Added | ||
|
|
||
| - `skipper add <alias> <user@host[:port]>` subcommand for writing a new host | ||
| entry to the SSH config. Inherits the `-c, --config` persistent flag. | ||
| - Idempotent re-runs of `skipper add` with the same alias and target now | ||
| report `host "<alias>" already exists ..., no change` instead of claiming | ||
| the entry was added. | ||
|
|
||
| ### Removed | ||
|
|
||
| - **BREAKING**: the `-a, --add` flag on the root command has been removed. | ||
| Migrate to the `add` subcommand: | ||
|
|
||
| ```bash | ||
| # before | ||
| skipper --add devone user@10.0.0.8:9000 | ||
|
|
||
| # after | ||
| skipper add devone user@10.0.0.8:9000 | ||
| ``` | ||
|
|
||
| ## [0.1.5] | ||
|
|
||
| - Previous releases are tracked in [GitHub Releases](https://github.com/JerryAgbesi/skipper/releases). | ||
|
|
||
| [0.1.5]: https://github.com/JerryAgbesi/skipper/releases/tag/v0.1.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var addCmd = &cobra.Command{ | ||
| Use: "add <alias> <user@host[:port]>", | ||
| Short: "Add a host entry to the SSH config", | ||
| Long: "Add a host entry to the SSH config under the given alias. The target must be in the form user@host[:port].", | ||
| Example: ` skipper add devone user@10.0.0.8:9000 | ||
| skipper add bastion admin@10.0.0.5`, | ||
| Args: cobra.ExactArgs(2), | ||
| RunE: runAdd, | ||
| } | ||
|
|
||
| func runAdd(_ *cobra.Command, args []string) error { | ||
| path, err := resolveConfigPath(configPath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| host, created, err := addHost(path, args[0], args[1]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if created { | ||
| fmt.Printf("added host %q for %s\n", host.Alias, hostTarget(host)) | ||
| } else { | ||
| fmt.Printf("host %q already exists for %s, no change\n", host.Alias, hostTarget(host)) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(addCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/jerryagbesi/skipper/internal/sshconfig" | ||
| ) | ||
|
|
||
| func TestAddCommandWritesHost(t *testing.T) { | ||
| path := filepath.Join(t.TempDir(), "config") | ||
|
|
||
| out := new(bytes.Buffer) | ||
| rootCmd.SetOut(out) | ||
| rootCmd.SetErr(out) | ||
| rootCmd.SetArgs([]string{"add", "devone", "user@10.0.0.8:9000", "-c", path}) | ||
|
|
||
| if err := rootCmd.Execute(); err != nil { | ||
| t.Fatalf("expected add command to succeed, got %v", err) | ||
| } | ||
|
|
||
| hosts, err := sshconfig.ParseHosts(path) | ||
| if err != nil { | ||
| t.Fatalf("expected config to parse, got %v", err) | ||
| } | ||
|
|
||
| if len(hosts) != 1 || hosts[0].Alias != "devone" { | ||
| t.Fatalf("expected single devone host, got %+v", hosts) | ||
| } | ||
| } | ||
|
|
||
| func TestAddCommandRejectsWrongArgCount(t *testing.T) { | ||
| path := filepath.Join(t.TempDir(), "config") | ||
|
|
||
| out := new(bytes.Buffer) | ||
| rootCmd.SetOut(out) | ||
| rootCmd.SetErr(out) | ||
| rootCmd.SetArgs([]string{"add", "devone", "-c", path}) | ||
|
|
||
| err := rootCmd.Execute() | ||
| if err == nil { | ||
| t.Fatal("expected error for missing target argument") | ||
| } | ||
|
|
||
| if !strings.Contains(err.Error(), "accepts 2 arg") { | ||
| t.Fatalf("expected arg-count error, got %v", err) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix spelling in this contributor guideline.
There’s a typo in “unnesessary”; it should be “unnecessary.”
Proposed patch
Based on learnings: Avoid using unnecessary emojis.
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~29-~29: Ensure spelling is correct
Context: ...behavior or flags change. - avoid using unnesessary emojis. ## Commit messages Short, imp...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🤖 Prompt for AI Agents