aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
blob: 436c7b7bb198a1cfeb72ee1acf3120fecce588af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main

import (
	"context"
	"flag"
	"log"
	"os"
	"os/signal"
	"syscall"
)

var (
	hostDir  = flag.String("host", "/host", "Host source directory (read-only)")
	dataDir  = flag.String("data", "/data", "Data destination directory")
	verbose  = flag.Bool("verbose", false, "Enable verbose logging")
	dryRun   = flag.Bool("dry-run", false, "Preview what would be synced without copying")
)

func main() {
	flag.Parse()
	log.SetFlags(log.LstdFlags | log.Lshortfile)

	if *verbose {
		log.Println("sourcewatch starting...")
		log.Printf("host: %s, data: %s, dry-run: %v", *hostDir, *dataDir, *dryRun)
	}

	rules, err := loadGitignore(*hostDir)
	if err != nil {
		log.Fatalf("failed to load .gitignore: %v", err)
	}

	manifest, err := initialSync(*hostDir, *dataDir, rules, *dryRun)
	if err != nil {
		log.Fatalf("initial sync failed: %v", err)
	}

	ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
	defer cancel()

	if err := watch(ctx, *hostDir, *dataDir, manifest, rules, *dryRun, *verbose); err != nil {
		log.Fatalf("watcher failed: %v", err)
	}
}