Skip to content

Commit

Permalink
Support recursive glob patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisPalnitsky committed Aug 27, 2024
1 parent c5e25e3 commit 108812e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ This will create a file named "file-for-ai.txt" in your current directory with t
You can also use a glob pattern:

``` bash
file-for-ai *.txt
file-for-ai ./**/*.txt
```

This will create a file named "file-for-ai.txt" in your current directory with the contents of all text files matching the pattern.
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.

To specify a custom output file name:

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.11.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/yargevad/filepathx v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/text v0.3.7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc=
github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
10 changes: 3 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/denormal/go-gitignore"
"github.com/yargevad/filepathx"

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

outputFileName := conf.OutputFile

if _, err := os.Stat(outputFileName); !os.IsNotExist(err) {
fmt.Printf("Output file %s already exists\n", outputFileName)
os.Exit(1)
}

outputFile, err := os.Create(outputFileName)
if err != nil {
fmt.Println("Error creating output file:", err)
Expand Down Expand Up @@ -87,7 +83,7 @@ func main() {
return processFile(inputPath, path, info, outputFile, tkm, &tokens, outputFileName)
})
} else {
files, err := filepath.Glob(inputPath)
files, err := filepathx.Glob(inputPath)
if err != nil {
fmt.Println("Error parsing glob pattern:", err)
os.Exit(1)
Expand Down

0 comments on commit 108812e

Please sign in to comment.