Skip to content

Commit

Permalink
Add build information in .ssh/config header (Fix #49)
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Mar 22, 2016
1 parent 84d32c7 commit 5f9a296
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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)
})
}

0 comments on commit 5f9a296

Please sign in to comment.