Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the path to stripmetadata configurable with a command line argument. #357

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dist/
**/plugin
**/cover.out
**/*.wasm
experiments/runs/**
experiments/runs/**
tools/stripmetadata/stripmetadata
7 changes: 6 additions & 1 deletion tools/stripmetadata/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ go 1.22.5
require (
github.com/Kunde21/markdownfmt/v3 v3.1.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.8.1
github.com/yuin/goldmark v1.7.4
)

require github.com/mattn/go-runewidth v0.0.9 // indirect
require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
9 changes: 9 additions & 0 deletions tools/stripmetadata/go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
github.com/Kunde21/markdownfmt/v3 v3.1.0 h1:KiZu9LKs+wFFBQKhrZJrFZwtLnCCWJahL+S+E/3VnM0=
github.com/Kunde21/markdownfmt/v3 v3.1.0/go.mod h1:tPXN1RTyOzJwhfHoon9wUr4HGYmWgVxSQN6VBJDkrVc=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg=
github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
36 changes: 20 additions & 16 deletions tools/stripmetadata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
markdownfmt "github.com/Kunde21/markdownfmt/v3/markdown"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -75,18 +76,7 @@ func processFile(ctx context.Context, path string) error {
return nil
}

func run() error {
cwd, err := os.Getwd()
if err != nil {
return errors.Wrapf(err, "Error getting current working directory")
}

rootDir, err := filepath.Abs(filepath.Join(cwd, "..", ".."))
if err != nil {
return errors.Wrapf(err, "Error getting root directory")
}
docsDir := filepath.Join(rootDir, "docs", "content")

func run(docsDir string) error {
mdFiles, err := findMDFiles(context.Background(), docsDir)
if err != nil {
return errors.Wrapf(err, "Error finding markdown files")
Expand All @@ -101,10 +91,24 @@ func run() error {
}

func main() {
if err := run(); err != nil {
fmt.Println("Error processing markdown: %+v", err)
os.Exit(1)
var docsDir string
var rootCmd = &cobra.Command{
Use: "markdown-processor",
Short: "Process markdown files to remove metadata from code blocks",
Run: func(cmd *cobra.Command, args []string) {
run(docsDir)
},
}

fmt.Println("Markdown processed successfully!")
cwd, err := os.Getwd()
if err != nil {
fmt.Printf("Error getting current working directory: %v\n", err)
cwd = "."
}
rootCmd.Flags().StringVarP(&docsDir, "path", "p", cwd, "Path to the directory containing markdown files")

if err := rootCmd.Execute(); err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}
}
Binary file removed tools/stripmetadata/stripmetadata
Binary file not shown.