From 11894f332b6a04492771680dbd351332ca2f0efd Mon Sep 17 00:00:00 2001 From: Rohit Nayak Date: Sun, 15 Dec 2024 15:12:04 +0100 Subject: [PATCH] Attempt to replace WORKDIR for all files which are generated Signed-off-by: Rohit Nayak --- go/cmd/internal/docgen/docgen.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/go/cmd/internal/docgen/docgen.go b/go/cmd/internal/docgen/docgen.go index 4a13a174f3d..0aa641a05f5 100644 --- a/go/cmd/internal/docgen/docgen.go +++ b/go/cmd/internal/docgen/docgen.go @@ -116,7 +116,6 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm fullCmdFilename := strings.Join([]string{name, cmd.Name()}, "_") children := cmd.Commands() - switch { case len(children) > 0: // Command (top-level or not) with children. @@ -151,7 +150,6 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm oldName := filepath.Join(rootDir, fullCmdFilename+".md") newName := filepath.Join(dir, fullCmdFilename+".md") - if err := os.Rename(oldName, newName); err != nil { return fmt.Errorf("failed to move child command %s to its parent's dir: %w", fullCmdFilename, err) } @@ -166,6 +164,16 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm } 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") + if err := anonymizeHomedir(f); err != nil { + return fmt.Errorf("failed to anonymize homedir in help text for command %s: %w", f, err) + } continue } }