Implement adding and tracking
This commit is contained in:
35
main.go
35
main.go
@@ -5,14 +5,15 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/bmatcuk/doublestar/v4"
|
||||
logger "git.site.quack-lab.dev/dave/cylogger"
|
||||
utils "git.site.quack-lab.dev/dave/cyutils"
|
||||
"github.com/bmatcuk/doublestar/v4"
|
||||
)
|
||||
|
||||
type ExtData struct {
|
||||
@@ -79,6 +80,38 @@ func main() {
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
if *track {
|
||||
logger.Info("Tracking results")
|
||||
extensionTypeCount.Range(func(key, value any) bool {
|
||||
extData := value.(*ExtData)
|
||||
extlog := logger.Default.WithPrefix(fmt.Sprintf("ext=%s", extData.ext))
|
||||
if extData.ext == "" {
|
||||
extlog.Debug("Skipping empty extension")
|
||||
return true
|
||||
}
|
||||
|
||||
cmd := exec.Command("git", "add", extData.ext)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
extlog.Error("Error adding extension: %v: %s", err, output)
|
||||
return true
|
||||
}
|
||||
extlog.Debug("Added extension")
|
||||
extlog.Trace("output: %s", output)
|
||||
|
||||
cmd = exec.Command("git", "commit", "-m", fmt.Sprintf("Track %s", extData.ext))
|
||||
output, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
extlog.Error("Error committing extension: %v: %s", err, output)
|
||||
return true
|
||||
}
|
||||
extlog.Debug("Committed extension")
|
||||
extlog.Trace("output: %s", output)
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// IsBinaryFile detects if a file is binary by analyzing a sample of its content
|
||||
|
||||
Reference in New Issue
Block a user