diff --git a/go/cmd/internal/docgen/docgen.go b/go/cmd/internal/docgen/docgen.go index f6c7e6b098d..b2777ff221a 100644 --- a/go/cmd/internal/docgen/docgen.go +++ b/go/cmd/internal/docgen/docgen.go @@ -85,10 +85,6 @@ func GenerateMarkdownTree(cmd *cobra.Command, dir string) error { return fmt.Errorf("failed to index doc (generated at %s) into proper position (%s): %w", rootDocPath, indexDocPath, err) } - if err := anonymizeHomedir(indexDocPath); err != nil { - return fmt.Errorf("failed to anonymize homedir in help text for command %s: %w", indexDocPath, err) - } - if err := restructure(dir, dir, cmd.Name(), cmd.Commands()); err != nil { return err } @@ -132,10 +128,6 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm return fmt.Errorf("failed to move index doc for command %s with children: %w", fullCmdFilename, err) } - if err := anonymizeHomedir(indexFile); err != nil { - return fmt.Errorf("failed to anonymize homedir in help text for command %s: %w", indexFile, err) - } - if err := restructure(rootDir, cmdDir, fullCmdFilename, children); err != nil { return fmt.Errorf("failed to restructure child commands for %s: %w", fullCmdFilename, err) } @@ -158,21 +150,6 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm if out, err := sed.CombinedOutput(); err != nil { return fmt.Errorf("failed to rewrite links to parent command in child %s: %w (extra: %s)", newName, err, out) } - - if err := anonymizeHomedir(newName); err != nil { - return fmt.Errorf("failed to anonymize homedir in help text for command %s: %w", newName, err) - } - default: - // Top-level command without children. Nothing to restructure. - // However we still need to anonymize the homedir in the help text. - if cmd.Name() == "help" { - // all commands with children have their own "help" subcommand, - // which we do not generate docs for - continue - } - f := filepath.Join(dir, fullCmdFilename+".md") - _ = anonymizeHomedir(f) // it is possible that the file does not exist, so we ignore the error - continue } } @@ -180,7 +157,7 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm } func newParentLinkSedCommand(parent string, file string) *exec.Cmd { - return exec.Command("sed", "-i", "", "-e", fmt.Sprintf("s:(./%s/):(../):i", parent), file) + return exec.Command("xyz", "-i", "-e", fmt.Sprintf("s:(./%s/):(../):i", parent), file) } var ( @@ -188,29 +165,6 @@ var ( once sync.Once ) -func anonymizeHomedir(file string) (err error) { - once.Do(func() { - // Only do this once per run. - wd, err = os.Getwd() - }) - if err != nil { - return err - } - if _, err := os.Stat(file); err != nil { - return nil - } - - // We're replacing the stuff inside the square brackets in the example sed - // below: - // 's:Paths to search for config files in. (default \[.*\])$:Paths to search for config files in. (default \[\]):' - sed := exec.Command("sed", "-i", "", "-e", fmt.Sprintf("s:%s:%s:", wd, ""), file) - if out, err := sed.CombinedOutput(); err != nil { - return fmt.Errorf("%w: %s", err, out) - } - - return nil -} - func recursivelyDisableAutoGenTags(root *cobra.Command) { commands := []*cobra.Command{root} for cmd := commands[0]; len(commands) > 0; cmd, commands = commands[0], commands[1:] {