Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tools/get_pack_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strings"

"github.com/buildpacks/pack/cmd"
"github.com/buildpacks/pack/pkg/logging"
"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
Expand Down Expand Up @@ -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 {
Expand Down
Loading