@@ -116,7 +116,6 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm
116
116
fullCmdFilename := strings .Join ([]string {name , cmd .Name ()}, "_" )
117
117
118
118
children := cmd .Commands ()
119
-
120
119
switch {
121
120
case len (children ) > 0 :
122
121
// Command (top-level or not) with children.
@@ -151,7 +150,6 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm
151
150
152
151
oldName := filepath .Join (rootDir , fullCmdFilename + ".md" )
153
152
newName := filepath .Join (dir , fullCmdFilename + ".md" )
154
-
155
153
if err := os .Rename (oldName , newName ); err != nil {
156
154
return fmt .Errorf ("failed to move child command %s to its parent's dir: %w" , fullCmdFilename , err )
157
155
}
@@ -166,6 +164,14 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm
166
164
}
167
165
default :
168
166
// Top-level command without children. Nothing to restructure.
167
+ // However we still need to anonymize the homedir in the help text.
168
+ if cmd .Name () == "help" {
169
+ // all commands with children have their own "help" subcommand,
170
+ // which we do not generate docs for
171
+ continue
172
+ }
173
+ f := filepath .Join (dir , fullCmdFilename + ".md" )
174
+ _ = anonymizeHomedir (f ) // it is possible that the file does not exist, so we ignore the error
169
175
continue
170
176
}
171
177
}
@@ -190,11 +196,14 @@ func anonymizeHomedir(file string) (err error) {
190
196
if err != nil {
191
197
return err
192
198
}
199
+ if _ , err := os .Stat (file ); err != nil {
200
+ return nil
201
+ }
193
202
194
203
// We're replacing the stuff inside the square brackets in the example sed
195
204
// below:
196
205
// 's:Paths to search for config files in. (default \[.*\])$:Paths to search for config files in. (default \[<WORKDIR>\]):'
197
- sed := exec .Command ("sed" , "-i" , "-e" , fmt .Sprintf ("s:%s:<WORKDIR>:i " , wd ), file )
206
+ sed := exec .Command ("sed" , "-i" , "" , " -e" , fmt .Sprintf ("s:%s:%s: " , wd , "<WORKDIR>" ), file )
198
207
if out , err := sed .CombinedOutput (); err != nil {
199
208
return fmt .Errorf ("%w: %s" , err , out )
200
209
}
@@ -224,7 +233,6 @@ func getCommitID(ref string) (string, error) {
224
233
const frontmatter = `---
225
234
title: %s
226
235
series: %s
227
- commit: %s
228
236
---
229
237
`
230
238
@@ -240,7 +248,7 @@ func frontmatterFilePrepender(sha string) func(filename string) string {
240
248
241
249
cmdName = strings .ReplaceAll (cmdName , "_" , " " )
242
250
243
- return fmt .Sprintf (frontmatter , cmdName , root , sha )
251
+ return fmt .Sprintf (frontmatter , cmdName , root )
244
252
}
245
253
}
246
254
0 commit comments