mdox icon indicating copy to clipboard operation
mdox copied to clipboard

feature: Get certain structure or function from file to md snippet.

Open bwplotka opened this issue 3 years ago • 3 comments
trafficstars

We often sed to point to certain structure. This is fragile as whenever code changes file, or lines were added before or structure adds or removes lines we have to manually find A - B in `sed -n 'A,,Bp'

It would be easy to just point to struct you want to print in whole package or module 🤗

bwplotka avatar Jul 13 '22 13:07 bwplotka

I have the same need, and for a PR in custom-metrics-apiserver (https://github.com/kubernetes-sigs/custom-metrics-apiserver/pull/138), I developed a small tool that prints snippets of Go files, to be used with mdox-exec.

I would be happy to use it to contribute it to mdox, as @dgrisonnet suggested.

Is the following syntax suitable?

```go mdox-go-file="main.go" mdox-go-snippets="type=MyStruct,func=main"
// it would print the type MyStruct and the main function (in that order) from main.go
```

However, I'm not sure having this (or having mdox-gen-go-struct in #60) really complies with Unix philosophy (do one thing, do it well)...

olivierlemasle avatar Jan 16 '23 09:01 olivierlemasle

I think this would fit well here, and addresses the sed fragility really well. I would love to see this addition! 🙂 I think mdox aims to fit really well with Go ecosystem in general, so we started initiatives like #60. Wdyt? cc: @bwplotka

saswatamcode avatar Jan 16 '23 09:01 saswatamcode

Lgtm (: let's aim for some short name of this though.. maybe mdox-go=MyStruct.MyMethod even.

bwplotka avatar Jan 16 '23 09:01 bwplotka