Commit inical 🚀

master v1
Juan Algaba 3 months ago
commit c1b428a513
  1. 32
      .gitignore
  2. 37
      README.md
  3. 5
      go.mod
  4. 2
      go.sum
  5. 83
      test_glob.go

32
.gitignore vendored

@ -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/

@ -0,0 +1,37 @@
# GLOB TESTER PARA GITEA
Probar expresiones `glob` de la misma manera que lo hace Gitea
<https://github.com/gobwas/glob>
## Instalar go
<https://go.dev/doc/install>
## 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

@ -0,0 +1,5 @@
module test_glob
go 1.25.1
require github.com/gobwas/glob v0.2.3

@ -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=

@ -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)
}
}
Loading…
Cancel
Save