@@ -85,10 +85,6 @@ func GenerateMarkdownTree(cmd *cobra.Command, dir string) error {
85
85
return fmt .Errorf ("failed to index doc (generated at %s) into proper position (%s): %w" , rootDocPath , indexDocPath , err )
86
86
}
87
87
88
- if err := anonymizeHomedir (indexDocPath ); err != nil {
89
- return fmt .Errorf ("failed to anonymize homedir in help text for command %s: %w" , indexDocPath , err )
90
- }
91
-
92
88
if err := restructure (dir , dir , cmd .Name (), cmd .Commands ()); err != nil {
93
89
return err
94
90
}
@@ -132,10 +128,6 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm
132
128
return fmt .Errorf ("failed to move index doc for command %s with children: %w" , fullCmdFilename , err )
133
129
}
134
130
135
- if err := anonymizeHomedir (indexFile ); err != nil {
136
- return fmt .Errorf ("failed to anonymize homedir in help text for command %s: %w" , indexFile , err )
137
- }
138
-
139
131
if err := restructure (rootDir , cmdDir , fullCmdFilename , children ); err != nil {
140
132
return fmt .Errorf ("failed to restructure child commands for %s: %w" , fullCmdFilename , err )
141
133
}
@@ -158,59 +150,21 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm
158
150
if out , err := sed .CombinedOutput (); err != nil {
159
151
return fmt .Errorf ("failed to rewrite links to parent command in child %s: %w (extra: %s)" , newName , err , out )
160
152
}
161
-
162
- if err := anonymizeHomedir (newName ); err != nil {
163
- return fmt .Errorf ("failed to anonymize homedir in help text for command %s: %w" , newName , err )
164
- }
165
- default :
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
175
- continue
176
153
}
177
154
}
178
155
179
156
return nil
180
157
}
181
158
182
159
func newParentLinkSedCommand (parent string , file string ) * exec.Cmd {
183
- return exec .Command ("sed " , "-i" , " " , "-e" , fmt .Sprintf ("s:(./%s/):(../):i" , parent ), file )
160
+ return exec .Command ("xyz " , "-i" , "-e" , fmt .Sprintf ("s:(./%s/):(../):i" , parent ), file )
184
161
}
185
162
186
163
var (
187
164
wd string
188
165
once sync.Once
189
166
)
190
167
191
- func anonymizeHomedir (file string ) (err error ) {
192
- once .Do (func () {
193
- // Only do this once per run.
194
- wd , err = os .Getwd ()
195
- })
196
- if err != nil {
197
- return err
198
- }
199
- if _ , err := os .Stat (file ); err != nil {
200
- return nil
201
- }
202
-
203
- // We're replacing the stuff inside the square brackets in the example sed
204
- // below:
205
- // 's:Paths to search for config files in. (default \[.*\])$:Paths to search for config files in. (default \[<WORKDIR>\]):'
206
- sed := exec .Command ("sed" , "-i" , "" , "-e" , fmt .Sprintf ("s:%s:%s:" , wd , "<WORKDIR>" ), file )
207
- if out , err := sed .CombinedOutput (); err != nil {
208
- return fmt .Errorf ("%w: %s" , err , out )
209
- }
210
-
211
- return nil
212
- }
213
-
214
168
func recursivelyDisableAutoGenTags (root * cobra.Command ) {
215
169
commands := []* cobra.Command {root }
216
170
for cmd := commands [0 ]; len (commands ) > 0 ; cmd , commands = commands [0 ], commands [1 :] {
0 commit comments