Repository navigation
Expand file tree
/
Copy pathdocgen.go
More file actions
49 lines (43 loc) · 1.47 KB
/
Copy pathdocgen.go
File metadata and controls
49 lines (43 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package capability
import (
"errors"
"fmt"
"os/exec"
"runtime/debug"
"strings"
"github.com/smartcontractkit/chainlink-common/x/config/commentparsing"
"github.com/smartcontractkit/chainlink-common/x/config/markup/tomlmarkup"
"github.com/spf13/cobra"
)
// newDocgenCmd generates the DocComments the flags' help text is read from, for every config the capability
// provides, so a capability's main can:
//
// //go:generate go run . docgen
func newDocgenCmd() *cobra.Command {
return &cobra.Command{
Use: "docgen",
Short: "Generate the doc comments of the capability's configs, for go:generate",
Args: cobra.NoArgs,
Hidden: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, _ []string) error {
info, ok := debug.ReadBuildInfo()
if !ok {
return errors.New("no build info to find the capability's module by")
}
out, err := exec.CommandContext(cmd.Context(), "go", "list", "-m").Output()
if err != nil {
return fmt.Errorf("failed to find the module docgen runs in: %w", err)
}
if mod := strings.TrimSpace(string(out)); mod != info.Main.Path {
return fmt.Errorf("docgen must run in %s, the capability's module, not %s", info.Main.Path, mod)
}
return commentparsing.Run(commentparsing.RunArgs{
Markup: tomlmarkup.New(),
Roots: append(RunInjector.Configs(), EmbedInjector.Configs()...),
Tool: info.Path + " docgen",
LocalPrefix: "github.com/smartcontractkit",
})
},
}
}