BurntSushi / toml

TOML parser for Golang with reflection.
MIT License
4.58k stars 528 forks source link

Support comments in encoding #75

Open joshlf opened 9 years ago

joshlf commented 9 years ago

Given that TOML supports comments, it would be nice if there were some way to emit TOML which included comments. My initial inclination was to implement the TextMarshaler interface, but it seems that doesn't work for key/value pairs (so you can't use it to omit a custom line of TOML).

My suggestion is that something be added which could be used to support this. I'm not sure what it would look like (a more flexible encoding mechanism? specific support for comments?), but it would be great to have.

joshlf commented 9 years ago

Actually, here's an idea: struct field tags define comments. Something like:

type Person struct {
    Name string `toml:"name,the peron's name"`
    Age  string `toml:"age,the person's age"`
}

(the idea is that the comma separates the key name and the comment; the tag toml:",comment" would be valid)

tucnak commented 8 years ago

Hugу +1 for this. @BurntSushi wanna push in?

yonderblue commented 8 years ago

+1

blackheart01 commented 7 years ago

Would love to have this feature. +1 from me.

jbsmith7741 commented 7 years ago

This is a great idea. It would be nice to separate the comment into an additional tag. For example we could use something like desc (description) or com (comment)

type Person struct {
    Name string `toml:"name" desc:"the person's name"`
    Age  string `toml:"age" desc:"the person's age"`
}
troian commented 5 years ago

@BurntSushi Is it still considered as feature request? I have reworked https://github.com/BurntSushi/toml/pull/97 a bit to support comment tag https://github.com/BurntSushi/toml/pull/235