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

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

Open
ycheng-git opened this issue May 27, 2022 · 2 comments

Comments

@ycheng-git
Copy link

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.

@kevinburke
Copy link
Owner

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?

@ycheng-git
Copy link
Author

ycheng-git commented Jun 28, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants