Skip to content

Commit 108812e

Browse files
Support recursive glob patterns
1 parent c5e25e3 commit 108812e

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ This will create a file named "file-for-ai.txt" in your current directory with t
2828
You can also use a glob pattern:
2929

3030
``` bash
31-
file-for-ai *.txt
31+
file-for-ai ./**/*.txt
3232
```
3333

34-
This will create a file named "file-for-ai.txt" in your current directory with the contents of all text files matching the pattern.
34+
This will create a file named "file-for-ai.txt" in your current directory with the contents of all txt files in the current directory and its subdirectories.
3535

3636
To specify a custom output file name:
3737

Diff for: go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ require (
3131
github.com/spf13/pflag v1.0.5 // indirect
3232
github.com/spf13/viper v1.11.0 // indirect
3333
github.com/subosito/gotenv v1.2.0 // indirect
34+
github.com/yargevad/filepathx v1.0.0 // indirect
3435
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
3536
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
3637
golang.org/x/text v0.3.7 // indirect

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
305305
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
306306
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
307307
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
308+
github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc=
309+
github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA=
308310
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
309311
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
310312
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

Diff for: main.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/denormal/go-gitignore"
10+
"github.com/yargevad/filepathx"
1011

1112
"github.com/num30/config"
1213
"github.com/pkoukk/tiktoken-go"
@@ -35,7 +36,7 @@ func main() {
3536
fmt.Println("Usage: file-for-ai <directory|pattern> --output [output file]")
3637
fmt.Println("\nExamples:")
3738
fmt.Println(" file-for-ai /path/to/directory")
38-
fmt.Println(" file-for-ai '*.txt'")
39+
fmt.Println(" file-for-ai './*.txt'")
3940
fmt.Println(" file-for-ai /path/to/directory --output custom-output.txt")
4041
fmt.Println("\nFor more information, visit https://github.com/num30/file-for-ai?tab=readme-ov-file#file-for-ai")
4142
os.Exit(1)
@@ -45,11 +46,6 @@ func main() {
4546

4647
outputFileName := conf.OutputFile
4748

48-
if _, err := os.Stat(outputFileName); !os.IsNotExist(err) {
49-
fmt.Printf("Output file %s already exists\n", outputFileName)
50-
os.Exit(1)
51-
}
52-
5349
outputFile, err := os.Create(outputFileName)
5450
if err != nil {
5551
fmt.Println("Error creating output file:", err)
@@ -87,7 +83,7 @@ func main() {
8783
return processFile(inputPath, path, info, outputFile, tkm, &tokens, outputFileName)
8884
})
8985
} else {
90-
files, err := filepath.Glob(inputPath)
86+
files, err := filepathx.Glob(inputPath)
9187
if err != nil {
9288
fmt.Println("Error parsing glob pattern:", err)
9389
os.Exit(1)

0 commit comments

Comments
 (0)