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

Generating markdown and html docs from the comments in go files #1264

Open
yp969803 opened this issue Mar 5, 2025 · 4 comments
Open

Generating markdown and html docs from the comments in go files #1264

yp969803 opened this issue Mar 5, 2025 · 4 comments
Labels
kind/enhancement New feature or request

Comments

@yp969803
Copy link
Contributor

yp969803 commented Mar 5, 2025

What would you like to be added:
We have to research, how can we parse comments in the go files to the markdown and html docs(html docs for the wesite)

  • We can write custom parsers
  • Is any go packages or tools available for the above, and if available what are the limitations

Why is this needed:
The KMesh project is currently in a sandboxed state and undergoes frequent updates, causing the documentation to become outdated over time. For example, the kmeshctl documentation on the website does not always reflect the latest changes. To ensure that the documentation remains accurate and up-to-date, we aim to automate the documentation creation process, reducing manual effort and improving consistency across updates.

@yp969803 yp969803 added the kind/enhancement New feature or request label Mar 5, 2025
@yp969803
Copy link
Contributor Author

yp969803 commented Mar 5, 2025

For kmeshctl we can use "github.com/spf13/cobra/doc", package

var multiplyCmd = &cobra.Command{
	Use:   "multiply [a] [b]",
	Short: "Multiply two numbers",
	Long:  `Multiplies two integers provided as arguments and prints the result.`,
	Args:  cobra.ExactArgs(2),
	Run: func(cmd *cobra.Command, args []string) {
		a := args[0]
		b := args[1]
		fmt.Printf("Result: %s * %s = %s\n", a, b, a)
	},
}

// GenerateDocs generates Markdown documentation
func GenerateDocs() error {
	// Directory to save the docs
	dir := "./docs"
	if err := os.MkdirAll(dir, 0755); err != nil {
		return err
	}
	// Generate Markdown files
	return doc.GenMarkdownTree(rootCmd, dir)
}

Result of generated markdown doc
generated in ./docs/mycli_multiply.md

Image

@yp969803
Copy link
Contributor Author

yp969803 commented Mar 5, 2025

We need more research, to get the best approach of doing this, all sugestions are welcome

@LiZhenCheng9527
Copy link
Collaborator

We have script that automatically generate markdown files based on kmeshctl comments.

https://github.com/kmesh-net/kmesh/blob/main/hack/gen-kmeshctl-doc.sh

@yp969803
Copy link
Contributor Author

yp969803 commented Mar 5, 2025

Oohk, we are using cobra go package for kmeshctl, let the issue be open so we can get more ideas of automating generating docs,

we also need generating monitoring docs based on below go code

tcpConnectionOpenedInWorkload = prometheus.NewGaugeVec(prometheus.GaugeOpts{
		Name: "kmesh_tcp_workload_connections_opened_total",
		Help: "The total number of TCP connections opened to a workload",
	}, workloadLabels)

	tcpConnectionClosedInWorkload = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "kmesh_tcp_workload_connections_closed_total",
			Help: "The total number of TCP connections closed to a workload",
		}, workloadLabels)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants