Add a dry run flag
This commit is contained in:
22
main.go
22
main.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user