ssh_config icon indicating copy to clipboard operation
ssh_config copied to clipboard

Since unable to set spaceBeforeComment, EOLComment is printed without any leading space in generated config

Open ycheng-git opened this issue 3 years ago • 2 comments

When generate a config, there is no way to set spaceBeforeComment, which cause the # and EOLComment is printed immediately after the pattern. We have to downgrade to v1.1.0.

ycheng-git avatar May 27 '22 06:05 ycheng-git

Can you say in a bit more detail? You want to generate a file that looks like

Host foo          # comment 

But you can only generate a file now that looks like

Host foo # comment

Is that right?

kevinburke avatar May 28 '22 15:05 kevinburke

No, the line will be generated as: Host foo# comment

Example:

package main

import (
	"fmt"

	"github.com/kevinburke/ssh_config"
)

func main() {
	nodes := []ssh_config.Node{
		&ssh_config.KV{Key: "  Hostname", Value: "1.2.3.4"},
		&ssh_config.KV{Key: "  Port", Value: "22"},
		&ssh_config.KV{Key: "  User", Value: "user"},
		&ssh_config.KV{Key: "  NumberOfPasswordPrompts", Value: "1"},
	}

	pattern, err := ssh_config.NewPattern("example")
	if err != nil {
		return
	}

	host := &ssh_config.Host{
		Patterns: []*ssh_config.Pattern{pattern},
		Nodes:    nodes,
	}
	host.EOLComment = "my comment"

	config := ssh_config.Config{
		Hosts: []*ssh_config.Host{host},
	}
	content, err := config.MarshalText()
	if err != nil {
		return
	}

	fmt.Println(string(content))
}

Output:

Host example#my comment
  Hostname 1.2.3.4
  Port 22
  User user
  NumberOfPasswordPrompts 1

ycheng-git avatar Jun 28 '22 07:06 ycheng-git