Skip to content

Commit d782732

Browse files
authored
Make the path to stripmetadata configurable with a command line argument. (#357)
* Remove the stripmetadata binary from the git repository.
1 parent 30f93c3 commit d782732

File tree

5 files changed

+37
-18
lines changed

5 files changed

+37
-18
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ dist/
1313
**/plugin
1414
**/cover.out
1515
**/*.wasm
16-
experiments/runs/**
16+
experiments/runs/**
17+
tools/stripmetadata/stripmetadata

tools/stripmetadata/go.mod

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ go 1.22.5
55
require (
66
github.com/Kunde21/markdownfmt/v3 v3.1.0
77
github.com/pkg/errors v0.9.1
8+
github.com/spf13/cobra v1.8.1
89
github.com/yuin/goldmark v1.7.4
910
)
1011

11-
require github.com/mattn/go-runewidth v0.0.9 // indirect
12+
require (
13+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
14+
github.com/mattn/go-runewidth v0.0.9 // indirect
15+
github.com/spf13/pflag v1.0.5 // indirect
16+
)

tools/stripmetadata/go.sum

+9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
github.com/Kunde21/markdownfmt/v3 v3.1.0 h1:KiZu9LKs+wFFBQKhrZJrFZwtLnCCWJahL+S+E/3VnM0=
22
github.com/Kunde21/markdownfmt/v3 v3.1.0/go.mod h1:tPXN1RTyOzJwhfHoon9wUr4HGYmWgVxSQN6VBJDkrVc=
3+
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
34
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
45
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
7+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
58
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
69
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
710
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
811
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
912
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1013
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
14+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
15+
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
16+
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
17+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
18+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
1119
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
1220
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
1321
github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg=
1422
github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
23+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1524
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
1625
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

tools/stripmetadata/main.go

+20-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
markdownfmt "github.com/Kunde21/markdownfmt/v3/markdown"
88
"github.com/pkg/errors"
9+
"github.com/spf13/cobra"
910
"os"
1011
"path/filepath"
1112
"strings"
@@ -75,18 +76,7 @@ func processFile(ctx context.Context, path string) error {
7576
return nil
7677
}
7778

78-
func run() error {
79-
cwd, err := os.Getwd()
80-
if err != nil {
81-
return errors.Wrapf(err, "Error getting current working directory")
82-
}
83-
84-
rootDir, err := filepath.Abs(filepath.Join(cwd, "..", ".."))
85-
if err != nil {
86-
return errors.Wrapf(err, "Error getting root directory")
87-
}
88-
docsDir := filepath.Join(rootDir, "docs", "content")
89-
79+
func run(docsDir string) error {
9080
mdFiles, err := findMDFiles(context.Background(), docsDir)
9181
if err != nil {
9282
return errors.Wrapf(err, "Error finding markdown files")
@@ -101,10 +91,24 @@ func run() error {
10191
}
10292

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

109-
fmt.Println("Markdown processed successfully!")
103+
cwd, err := os.Getwd()
104+
if err != nil {
105+
fmt.Printf("Error getting current working directory: %v\n", err)
106+
cwd = "."
107+
}
108+
rootCmd.Flags().StringVarP(&docsDir, "path", "p", cwd, "Path to the directory containing markdown files")
109+
110+
if err := rootCmd.Execute(); err != nil {
111+
fmt.Printf("Error: %v\n", err)
112+
os.Exit(1)
113+
}
110114
}

tools/stripmetadata/stripmetadata

-4.37 MB
Binary file not shown.

0 commit comments

Comments
 (0)