MCPcopy Index your code
hub / github.com/coder/coder / init

Function init

scripts/clidocgen/gen.go:25–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23var commandTemplate *template.Template
24
25func init() {
26 commandTemplate = template.Must(
27 template.New("command.tpl").Funcs(template.FuncMap{
28 "visibleSubcommands": func(cmd *serpent.Command) []*serpent.Command {
29 var visible []*serpent.Command
30 for _, sub := range cmd.Children {
31 if sub.Hidden {
32 continue
33 }
34 visible = append(visible, sub)
35 }
36 return visible
37 },
38 "visibleOptions": func(cmd *serpent.Command) []serpent.Option {
39 var visible []serpent.Option
40 for _, opt := range cmd.Options {
41 if opt.Hidden {
42 continue
43 }
44 visible = append(visible, opt)
45 }
46 return visible
47 },
48 "atRoot": func(cmd *serpent.Command) bool {
49 return cmd.FullName() == "coder"
50 },
51 "newLinesToBr": func(s string) string {
52 return strings.ReplaceAll(s, "\n", "<br/>")
53 },
54 "wrapCode": func(s string) string {
55 return fmt.Sprintf("<code>%s</code>", s)
56 },
57 "commandURI": fmtDocFilename,
58 "fullName": fullName,
59 "tableHeader": func() string {
60 return `| | |
61| --- | --- |`
62 },
63 "typeHelper": func(opt *serpent.Option) string {
64 switch v := opt.Value.(type) {
65 case *serpent.Enum:
66 return strings.Join(v.Choices, "\\|")
67 case *serpent.EnumArray:
68 return fmt.Sprintf("[%s]", strings.Join(v.Choices, "\\|"))
69 default:
70 return v.Type()
71 }
72 },
73 },
74 ).Parse(strings.TrimSpace(commandTemplateRaw)),
75 )
76}
77
78func fullName(cmd *serpent.Command) string {
79 if cmd.FullName() == "coder" {

Callers

nothing calls this directly

Calls 4

ParseMethod · 0.65
NewMethod · 0.65
TypeMethod · 0.65
FullNameMethod · 0.45

Tested by

no test coverage detected