From c1b428a513ba9be37bcec6bc78991c11378c2b9d Mon Sep 17 00:00:00 2001 From: Juan Algaba Date: Wed, 17 Sep 2025 15:23:51 -0700 Subject: [PATCH] =?UTF-8?q?Commit=20inical=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 32 ++++++++++++++++++++ README.md | 37 +++++++++++++++++++++++ go.mod | 5 ++++ go.sum | 2 ++ test_glob.go | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 159 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 go.mod create mode 100644 go.sum create mode 100644 test_glob.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c187cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib + +# Test binary, build output +*.test +*.out + +# Output of the go coverage tool +*.coverprofile + +# Dependency directories (remove the comment below if you use Go modules) +vendor/ + +# Go workspace file +go.work +go.work.sum + +# IDE/editor files +.vscode/ +.idea/ +*.swp +*.sublime-workspace +*.sublime-project + +# Logs +*.log + +#binary +bin/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..64b1098 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# GLOB TESTER PARA GITEA + +Probar expresiones `glob` de la misma manera que lo hace Gitea + + + +## Instalar go + + + +## Descargar dependencias + +```pwsh +go install +``` + +## Build executable para windows + +```pwsh +go build -o 'bin/test_glob.exe' 'test_glob.go' +``` + +## Usar + +```bash +cd ~/repos/sia-sipa-enlace +~/repos/go/bin/test_glob.exe "nbproject/**" +#nbproject/ant-deploy.xml +#nbproject/build-impl.xml +#nbproject/genfiles.properties +#etc... +``` + +## TO-DO + +* Ejecutable para linux +* 2do parĂ¡metro para especificar working directory diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..44f8268 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module test_glob + +go 1.25.1 + +require github.com/gobwas/glob v0.2.3 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..39fa9fa --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= +github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= diff --git a/test_glob.go b/test_glob.go new file mode 100644 index 0000000..e7690c0 --- /dev/null +++ b/test_glob.go @@ -0,0 +1,83 @@ +package main + +import ( + "fmt" + "log" + "os" + "path/filepath" + + "github.com/gobwas/glob" +) + +func main() { + // Default values + var targetDir string + var pattern string + + // Check if running from command line (has arguments) + if len(os.Args) > 1 { + // Command line mode: use current directory and pattern from args + targetDir = "." + pattern = os.Args[1] + fmt.Printf("Command line mode: searching for pattern '%s' in current directory\n", pattern) + } else { + // VS Code/IDE mode: use hardcoded values + targetDir = `C:\Users\jalgaba\repos\sia-sipa-enlace` + pattern = "nbproject/**" + fmt.Printf("IDE mode: searching for pattern '%s' in %s\n", pattern, targetDir) + + // Change to the target directory + err := os.Chdir(targetDir) //Change working directory + if err != nil { + log.Fatalf("failed to change directory to %s: %v", targetDir, err) + } + targetDir = "." // Now use current directory after chdir + } + + // Compile the glob pattern + compiledPattern, err := glob.Compile(pattern) + if err != nil { + log.Fatalf("failed to compile glob pattern '%s': %v", pattern, err) + } + + // Walk the directory tree + err = filepath.Walk(targetDir, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + // Get relative path for pattern matching + // We need relative paths because glob patterns like "nbproject/**" + // are relative, not absolute paths + var relPath string + if targetDir == "." { + // When walking from current directory ".", filepath.Walk already + // gives us relative paths like "file.txt" or "subfolder/file.txt" + relPath = path + } else { + // When walking from an absolute path like "/home/user/project", + // filepath.Walk gives us absolute paths, so we need to convert + // them back to relative paths for pattern matching + var err error + relPath, err = filepath.Rel(targetDir, path) + if err != nil { + return err + } + } + + // Normalize path separators and skip root directory + clean := filepath.ToSlash(relPath) + if clean == "." { + return nil + } + + // Test against pattern + if compiledPattern.Match(clean) { + fmt.Println(clean) + } + return nil + }) + if err != nil { + log.Fatalf("error walking path: %v", err) + } +}