]> Cypherpunks.ru repositories - goredo.git/commitdiff
cleanup -dry-run v1.1.0
authorSergey Matveev <stargrave@stargrave.org>
Fri, 22 Jan 2021 10:57:34 +0000 (13:57 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 22 Jan 2021 10:57:34 +0000 (13:57 +0300)
cleanup.go
doc/news.texi
usage.go

index 2c4268c9a785df2c54eee40932d403ceeb4910cd..61f028f2d56dc6d600a1146ff1ac7d640f5cef56 100644 (file)
@@ -18,6 +18,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 package main
 
 import (
+       "flag"
        "fmt"
        "io"
        "log"
@@ -33,6 +34,10 @@ const (
        CleanupTmp  = "tmp"
 )
 
+var (
+       DryRun = flag.Bool("dry-run", false, "do no delete files during cleanup, just show them")
+)
+
 func redoDirClean(root, what string) error {
        root, err := filepath.Abs(root)
        if err != nil {
@@ -57,15 +62,19 @@ func redoDirClean(root, what string) error {
                        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 @@ func cleanupWalker(root, what string) error {
                                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 @@ func cleanupWalker(root, what string) error {
                        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
+                                       }
                                }
                        }
                }
index 3d5a651f10d24dd4466f3bed9dbda8bbe8be1d6c..99faedaf6cc4d052aca934cfe1dff9ca1652a0e9 100644 (file)
@@ -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
index 5948b691045bda4e6ea37b138c11768b209e41a0..d31db406f97f35b5389056ef97cfc3ac97923ce4 100644 (file)
--- a/usage.go
+++ b/usage.go
@@ -26,7 +26,7 @@ import (
 )
 
 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 @@ You can create them by running: goredo -symlinks.
   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 [...]