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 build information in .ssh/config header (Fix #49) #138

Merged
merged 1 commit into from
Mar 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ Get a released version on: https://github.com/moul/advanced-ssh-config/releases

### master (unreleased)

* Add build information in .ssh/config header ([#49](https://github.com/moul/advanced-ssh-config/issues/49))
* Initial `Aliases` support ([#133](https://github.com/moul/advanced-ssh-config/issues/133))
* Use args[0] as ProxyCommand ([#134](https://github.com/moul/advanced-ssh-config/issues/134))
* Add `NoControlMasterMkdir` option to disable automatic creation of directories for gateways ([#124](https://github.com/moul/advanced-ssh-config/issues/124))
Expand Down
12 changes: 11 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import (
"path/filepath"
"sort"
"strings"
"time"

"github.com/moul/advanced-ssh-config/pkg/flexyaml"
. "github.com/moul/advanced-ssh-config/pkg/logger"
"github.com/moul/advanced-ssh-config/pkg/version"
)

var ASSHBinary = "assh"
Expand Down Expand Up @@ -317,7 +319,15 @@ func (c *Config) sortedNames() []string {

// ExportSshConfig returns a .ssh/config valid file containing assh configuration
func (c *Config) WriteSshConfigTo(w io.Writer) error {
fmt.Fprintln(w, "# ssh config generated by advanced-ssh-config")
header := strings.TrimSpace(`
# This file was automatically generated by assh v%VERSION
# on %BUILD_DATE, based on ~/.ssh/assh.yml
#
# more info: https://github.com/moul/advanced-ssh-config
`)
header = strings.Replace(header, "%VERSION", version.VERSION, -1)
header = strings.Replace(header, "%BUILD_DATE", time.Now().Format("2006-01-02 15:04:05 -0700 MST"), -1)
fmt.Fprintln(w, header)
// FIXME: add version
fmt.Fprintln(w)

Expand Down
5 changes: 3 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ func TestConfig_WriteSshConfig(t *testing.T) {
err := config.WriteSshConfigTo(&buffer)
So(err, ShouldBeNil)

expected := `# ssh config generated by advanced-ssh-config
expected := `# more info: https://github.com/moul/advanced-ssh-config

# host-based configuration
Host *.ddd
Expand Down Expand Up @@ -1319,6 +1319,7 @@ Host *
User root
ProxyCommand assh proxy --port=%p %h
`
So(buffer.String(), ShouldEqual, expected)
output := strings.Join(strings.Split(buffer.String(), "\n")[3:], "\n")
So(output, ShouldEqual, expected)
})
}