Add a dry run flag

This commit is contained in:
2025-11-20 15:29:27 +01:00
parent 079fc82ab9
commit 1eda2fcc82
4 changed files with 262 additions and 12 deletions

22
main.go
View File

@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"sync/atomic"
utils "git.site.quack-lab.dev/dave/cyutils"
)
@@ -27,11 +28,19 @@ func main() {
file := flag.String("f", "", "file to read instructions from")
debug := flag.Bool("d", false, "debug")
undoF := flag.Bool("u", false, "undo")
dryRun := flag.Bool("n", false, "dry run (no filesystem changes)")
flag.Parse()
undo = *undoF
setupLogging(*debug)
if *dryRun {
filesystem = NewDryRunFileSystem()
LogInfo("Dry run mode enabled - no filesystem changes will be made")
} else {
filesystem = NewRealFileSystem()
}
instructions := make(chan *LinkInstruction, 1000)
status := make(chan error)
@@ -43,9 +52,11 @@ func main() {
if instructionsDone == 0 {
LogInfo("No instructions were processed")
printSummary(filesystem)
os.Exit(1)
}
LogInfo("All done")
printSummary(filesystem)
}
// setupLogging configures logging based on debug flag
@@ -162,6 +173,17 @@ func processInstructions(instructions chan *LinkInstruction) int32 {
return instructionsDone
}
func printSummary(fs FileSystem) {
lines := fs.SummaryLines()
if len(lines) == 0 {
return
}
LogInfo("Summary:")
for _, line := range lines {
LogInfo("%s", line)
}
}
func IsPipeInput() bool {
info, err := os.Stdin.Stat()
if err != nil {