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

[WIP] docs: script for generating config docs #4292

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lookharm
Copy link

This pr introduces an initial solution to extract comments associated with a Config struct and then generate the config docs. The current implementation only supports single-level structs; nested structs are not supported yet. It will solve issue #4274. If this initial approach is accepted, I plan to make it complete.

A few questions to make it clearer:

  • Where will be this script placed? Should it be in docs/generate.go?

(cc @jedevc)

Signed-off-by: Woradorn Laodhanadhaworn <[email protected]>
@lookharm lookharm changed the title docs: script for generating config docs [WIP] docs: script for generating config docs Sep 29, 2023
@lookharm lookharm marked this pull request as draft September 29, 2023 07:13
@jedevc jedevc linked an issue Sep 30, 2023 that may be closed by this pull request
@jedevc
Copy link
Member

jedevc commented Sep 30, 2023

Heya @lookharm 👋 Thanks so much for giving this a go - nice work so far! 🎉

The only thing that you don't have there that I think would be really nice would be a way of printing out values from the target Config{} struct. With that, we could put down the existing sample configuration into code, and then print it all out with the comments 🎉

BTW - if you don't mind me asking, how did you come across the issue? I genuinely wasn't expecting anyone to pick it up so soon, so thanks!

Where will be this script placed? Should it be in docs/generate.go?

The logic in docs/generate.go is quite generic at the moment - it just replaces the contents of a <!---GENERATE_START <cmd>--> block with the output of running that <cmd> (see #3747 for where it was initially added). Ideally, we wouldn't need to update that, we'd just need to write our own little tool that prints out the config structure and some helpful messages for it.

I'm not sure where the little tool to do this would be though - for now, feel free to put it anywhere (like under docs/generate/config/config.go) - we can change it later.

Then we'd just do something like this in config.md:

This is the format of the config file:

<!---GENERATE_START go run ./generate/config/config.go-->
<!---GENERATE_END-->

@lookharm
Copy link
Author

lookharm commented Oct 1, 2023

Thanks for the response. After thinking about this.

I think it would be really nice would be a way of printing out values from the target Config{} struct.

According to go-tomal documentation https://pkg.go.dev/github.com/pelletier/[email protected]#Marshal. Don't you think this should be done with the TOML marshaler? For example,

type Config struct {
  Debug true `toml: "debug", comment: "Debug is bool"`
}

func main() {
  out, _ := toml.Marshal(Config{Debug: true})
  fmt.Println(string(out))
}

The output is:

# Debug is bool
debug = true

This way, it is easier and doesn't require any TOML parsing that go-toml package has done.

BTW - if you don't mind me asking, how did you come across the issue? I genuinely wasn't expecting anyone to pick it up so soon, so thanks!

I often use Docker and just want to learn more about how the internal works, I hope the contributions will help me, and I think the buildkit is a good starting point. If any issues that you see are good for the starter, please tell me.

@jedevc
Copy link
Member

jedevc commented Oct 1, 2023

Ahhh the TOML marshaller would be nice - but, I don't really like the pattern of reading the comments from a separate field. It means everything has to be in a sine line, which is not very easy to read or edit.

If we could keep the comments as go-style doc comments, I think using the TOML marshaller would be perfect! That said, I'd be happy to be persuaded if there's really no easy way to do this in code.

@jedevc
Copy link
Member

jedevc commented Nov 1, 2023

@lookharm just wanted to check-in - are you blocked on this, anything you need help with from our end? No rush, I've just been thinking about improving the config docs as well, and this was on-theme with that.

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

Successfully merging this pull request may close these issues.

Auto-generate config docs from code
2 participants