cleanup.go | 27 ++++++++++++++++++++------- doc/news.texi | 7 +++++++ usage.go | 4 ++-- diff --git a/cleanup.go b/cleanup.go index dc5837eac8b52009053bf0850c34f893bfb2107fc83bd34c1228f3dc663d7d85..b2dce227b24d88cd07408f0a48a1e1fee9040136b26cc853ce497825c75dd333 100644 --- a/cleanup.go +++ b/cleanup.go @@ -18,6 +18,7 @@ package main import ( + "flag" "fmt" "io" "log" @@ -31,6 +32,10 @@ const ( CleanupFull = "full" CleanupLog = "log" CleanupTmp = "tmp" +) + +var ( + DryRun = flag.Bool("dry-run", false, "do no delete files during cleanup, just show them") ) func redoDirClean(root, what string) error { @@ -57,15 +62,19 @@ switch what { case CleanupLog: if strings.HasSuffix(fi.Name(), LogSuffix) { fmt.Println(pth) - if err = os.Remove(pth); err != nil { - return err + if !*DryRun { + if err = os.Remove(pth); err != nil { + return err + } } } case CleanupTmp: if strings.HasPrefix(fi.Name(), TmpPrefix) { fmt.Println(pth) - if err = os.Remove(pth); err != nil { - return err + if !*DryRun { + if err = os.Remove(pth); err != nil { + return err + } } } default: @@ -101,7 +110,9 @@ if fi.IsDir() { if fi.Name() == RedoDir { if what == CleanupFull { fmt.Println(pthRel) - err = os.RemoveAll(pth) + if !*DryRun { + err = os.RemoveAll(pth) + } } else { err = redoDirClean(pth, what) } @@ -116,8 +127,10 @@ } if (what == CleanupTmp || what == CleanupFull) && strings.HasPrefix(fi.Name(), TmpPrefix) { fmt.Println(pthRel) - if err = os.Remove(pth); err != nil { - return err + if !*DryRun { + if err = os.Remove(pth); err != nil { + return err + } } } } diff --git a/doc/news.texi b/doc/news.texi index b859a7392b783fee8314ac9da96d635d7afb93619c8a5910248e26fb7b2f078f..8412e026ec264b73a9c6a3606411546128c8264cda02da7487b865328d0af8cd 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -1,6 +1,13 @@ @node News @unnumbered News +@anchor{Release 1.1.0} +@section Release 1.1.0 +@itemize +@item + @command{redo-cleanup} has @option{-dry-run} option. +@end itemize + @anchor{Release 1.0.0} @section Release 1.0.0 @itemize diff --git a/usage.go b/usage.go index cfc1b0dec312771f413772274c95a60c1263fc67558d4e312ddc4815d1387988..e522f94e0440eab3cfb8c2c6159729fd4ea10b13e9146358f001a4d4d2ccf2de 100644 --- a/usage.go +++ b/usage.go @@ -26,7 +26,7 @@ "strings" ) const ( - Version = "1.0.0" + Version = "1.1.0" Warranty = `This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License. @@ -61,7 +61,7 @@ * redo [options] [target ...] forcefully and *sequentially* build specified targets * redo-always always build current target. Unusable outside .do -* redo-cleanup {full,log,tmp} [...] +* redo-cleanup [-dry-run] {full,log,tmp} [...] remove either all goredo's related temporary files, or kept stderr logs, or everything (including .redo directories) related * redo-dot target [...]