From ef0bcbec34af4a96f1155f88356665d104fce1f7 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Mon, 1 Dec 2025 13:20:44 +1100 Subject: [PATCH] add in globbing support --- main.go | 14 +++++++++++++- test-all.sh | 9 +++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 28b960a..86b95f7 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ package main import ( "os" + "path/filepath" "runtime" "github.com/boyter/hashit/processor" @@ -21,7 +22,18 @@ func main() { Long: "Hash It!\nVersion " + processor.Version + "\nBen Boyter ", Version: processor.Version, Run: func(cmd *cobra.Command, args []string) { - processor.DirFilePaths = args + var filePaths []string + for _, arg := range args { + matches, err := filepath.Glob(arg) + if err != nil || len(matches) == 0 { + // If there's an error or no matches, treat the argument as a literal path + filePaths = append(filePaths, arg) + } else { + filePaths = append(filePaths, matches...) + } + } + + processor.DirFilePaths = filePaths processor.Process() }, } diff --git a/test-all.sh b/test-all.sh index 103abfa..356fc09 100755 --- a/test-all.sh +++ b/test-all.sh @@ -43,6 +43,15 @@ else exit fi +if ./hashit "*.go" | grep -q -i 'main.go'; then + echo -e "${GREEN}PASSED globbing test for *.go" +else + echo -e "${RED}=======================================================" + echo -e "FAILED Globbing test for *.go" + echo -e "=======================================================" + exit +fi + if ./hashit --debug --trace --verbose -f text --hash md5 --no-stream --stream-size 10 -r main.go > /dev/null ; then echo -e "${GREEN}PASSED multiple options test" else