From e3c0cd92d8345d1f30e245ea1dabb1e7f67e6d5e Mon Sep 17 00:00:00 2001 From: Lorenzo Campanella Date: Wed, 27 May 2026 17:02:45 -0400 Subject: [PATCH] docs: Fix ANSI escape sequences in pack CLI leaking into documentation (#891) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The get_pack_commands.go generator uses cobra/doc.GenMarkdownTreeCustom to produce markdown from the pack command tree. Some pack commands include ANSI color codes in their description strings (e.g. \x1b[94m...\x1b[0m) to improve terminal --help readability. These codes were passing through the generator unmodified and appearing as noise in the rendered documentation. Added a post-generation step that walks the output directory and strips SGR ANSI escape sequences (\x1b\[[0-9;]*m) from all generated .md files. This is the appropriate place to handle the conversion — the generator is the boundary between terminal output and markdown, and stripping color codes there keeps the fix localized without affecting the upstream CLI's terminal experience. Three files were affected: pack_config_pull-policy.md, pack_config_lifecycle-image.md, and pack_config_registries_default.md. Signed-off-by: Lorenzo Campanella --- tools/get_pack_commands.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tools/get_pack_commands.go b/tools/get_pack_commands.go index fe861016a..df023437f 100644 --- a/tools/get_pack_commands.go +++ b/tools/get_pack_commands.go @@ -7,6 +7,7 @@ import ( "os" "path" "path/filepath" + "regexp" "strings" "github.com/buildpacks/pack/cmd" @@ -14,6 +15,8 @@ import ( "github.com/spf13/cobra/doc" ) +var ansiEscape = regexp.MustCompile(`\x1b\[[0-9;]*m`) + const ( cliDir = "/docs/for-platform-operators/how-to/integrate-ci/pack/cli/" outputPath = "../content" + cliDir @@ -64,6 +67,27 @@ func main() { if err != nil { log.Fatal(err) } + + if err := stripANSIFromDir(outputPath); err != nil { + log.Fatal(err) + } +} + +func stripANSIFromDir(dir string) error { + return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + if err != nil || info.IsDir() || filepath.Ext(path) != ".md" { + return err + } + data, err := os.ReadFile(path) + if err != nil { + return err + } + cleaned := ansiEscape.ReplaceAll(data, nil) + if len(cleaned) == len(data) { + return nil + } + return os.WriteFile(path, cleaned, info.Mode()) + }) } type packLogger struct {