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

comment in struct #184

Closed
yesnault opened this issue Sep 7, 2017 · 3 comments · Fixed by #185
Closed

comment in struct #184

yesnault opened this issue Sep 7, 2017 · 3 comments · Fixed by #185
Labels
feature Issue asking for a new feature in go-toml.

Comments

@yesnault
Copy link
Contributor

yesnault commented Sep 7, 2017

Hi,

Do you plan to do something like this:

type Postgres struct {
    User     string `comment:"A comment on user"`
    Password string  `comment:"A comment on password"`
}

for

[postgres]
# A comment on user
user = ""
# A comment on password
password = ""

Or is there a way to add comment in output ?

Thks

@yesnault
Copy link
Contributor Author

yesnault commented Sep 11, 2017

with PR, it's that:

type TypeC struct {
	my string
}
type TypeB struct {
	AttrA string  `toml:"user" comment:"A comment on AttrA"`
	AttrB string  `toml:"password" comment:"A comment on AttrB"`
	AttrC string  `toml:"noComment"`
	My    []TypeC `comment:"a comment on My"`
}
type TypeA struct {
	TypeB TypeB `toml:"postgres" comment:"it's a comment on type"`
}

marshall ->

# postgres it's a comment on type
[postgres]
  noComment = "cvalue"

  # A comment on AttrB
  password = "bvalue"

  # A comment on AttrA
  user = "avalue"

  # a comment on My
  [[postgres.My]]

  # a comment on My
  [[postgres.My]]

@yesnault
Copy link
Contributor Author

type TypeC struct {
		My string `comment:"a comment on my on typeC"`
	}
	type TypeB struct {
		AttrA string  `toml:"user" comment:"A comment on AttrA"`
		AttrB string  `toml:"password" comment:"A comment on AttrB with a\n break line"`
		AttrC string  `toml:"noComment"`
		AttrD string  `toml:"isCommented" commented:"true"`
		My    []TypeC `comment:"a comment on My"`
	}
	type TypeA struct {
		TypeB TypeB `toml:"postgres" comment:"it's a comment on type"`
	}

	ta := []TypeC{{My: "Foo"}, {My: "Baar"}}
	config := TypeA{TypeB{AttrA: "avalue", AttrB: "bvalue", AttrC: "cvalue", AttrD: "dvalue", My: ta}}
	result, err := Marshal(config)

will returns:

# it's a comment on type
[postgres]
  # isCommented = "dvalue"
  noComment = "cvalue"

  # A comment on AttrB with a
  # break line
  password = "bvalue"

  # A comment on AttrA
  user = "avalue"

  # a comment on My
  [[postgres.My]]

    # a comment on my on typeC
    My = "Foo"

  [[postgres.My]]

    # a comment on my on typeC
    My = "Baar"

@pelletier
Copy link
Owner

Love it! Will review the PR shortly.

@pelletier pelletier added the feature Issue asking for a new feature in go-toml. label Sep 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issue asking for a new feature in go-toml.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants