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

Function writeCommand

scripts/clidocgen/gen.go:94–121  ·  view source on GitHub ↗
(w io.Writer, cmd *serpent.Command)

Source from the content-addressed store, hash-verified

92}
93
94func writeCommand(w io.Writer, cmd *serpent.Command) error {
95 var b strings.Builder
96 err := commandTemplate.Execute(&b, cmd)
97 if err != nil {
98 return err
99 }
100 content := stripansi.Strip(b.String())
101
102 // Remove the version and its right space, since during this script running
103 // there is no build info available
104 content = strings.ReplaceAll(content, buildinfo.Version()+" ", "")
105
106 // Remove references to the current working directory
107 cwd, err := os.Getwd()
108 if err != nil {
109 return err
110 }
111 content = strings.ReplaceAll(content, cwd, ".")
112
113 homedir, err := os.UserHomeDir()
114 if err != nil {
115 return err
116 }
117 content = strings.ReplaceAll(content, homedir, "~")
118
119 _, err = w.Write([]byte(content))
120 return err
121}
122
123func genTree(dir string, cmd *serpent.Command, wroteLog map[string]*serpent.Command) error {
124 if cmd.Hidden {

Callers 1

genTreeFunction · 0.85

Calls 4

VersionFunction · 0.92
ExecuteMethod · 0.65
WriteMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected