Skip to content

Commit ba75e4e

Browse files
authored
Merge pull request #23 from boyter/globbing
add in globbing support
2 parents 3f55d87 + ef0bcbe commit ba75e4e

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package main
44

55
import (
66
"os"
7+
"path/filepath"
78
"runtime"
89

910
"github.com/boyter/hashit/processor"
@@ -21,7 +22,18 @@ func main() {
2122
Long: "Hash It!\nVersion " + processor.Version + "\nBen Boyter <ben@boyter.org>",
2223
Version: processor.Version,
2324
Run: func(cmd *cobra.Command, args []string) {
24-
processor.DirFilePaths = args
25+
var filePaths []string
26+
for _, arg := range args {
27+
matches, err := filepath.Glob(arg)
28+
if err != nil || len(matches) == 0 {
29+
// If there's an error or no matches, treat the argument as a literal path
30+
filePaths = append(filePaths, arg)
31+
} else {
32+
filePaths = append(filePaths, matches...)
33+
}
34+
}
35+
36+
processor.DirFilePaths = filePaths
2537
processor.Process()
2638
},
2739
}

test-all.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ else
4343
exit
4444
fi
4545

46+
if ./hashit "*.go" | grep -q -i 'main.go'; then
47+
echo -e "${GREEN}PASSED globbing test for *.go"
48+
else
49+
echo -e "${RED}======================================================="
50+
echo -e "FAILED Globbing test for *.go"
51+
echo -e "======================================================="
52+
exit
53+
fi
54+
4655
if ./hashit --debug --trace --verbose -f text --hash md5 --no-stream --stream-size 10 -r main.go > /dev/null ; then
4756
echo -e "${GREEN}PASSED multiple options test"
4857
else

0 commit comments

Comments
 (0)