commit: ecd3ce545d376f577b66e3361caad00565a6ec5b
parent: 4d3f4ced2f4b1df31290267232d543239d2b6779
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 12 Dec 2019 00:46:58 +0100
Add -n flag
Diffstat:
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/go-deblob.1 b/go-deblob.1
@@ -9,6 +9,7 @@
.Nd remove binary blobs from a directory
.Sh SYNOPSIS
.Nm
+.Op Fl n
.Op Fl e Ar excluded paths
.Op Fl d Ar working directory
.Sh DESCRIPTION
@@ -20,6 +21,8 @@ already exists.
.Pp
The options are as follows:
.Bl -tag -width Ds
+.It Fl n
+Scan the files but do not actually delete them.
.It Fl e Ar excluded paths
Paths to be excluded from the scan, accepts shell globbing with Golang path.Match. Pass the option multiple times to do multiple exclusions.
.It Fl d Ar working directory
diff --git a/go-deblob.go b/go-deblob.go
@@ -14,6 +14,7 @@ import (
)
var excludes []string
+var noop bool
func isBlob(filename string) (result bool) {
result = false
@@ -75,6 +76,9 @@ func checkDir(dirname string) {
checkDir(filename)
} else if isBlob(filename) {
fmt.Printf("- %s", filename)
+ if noop {
+ continue
+ }
err = os.Remove(filename)
if err != nil {
log.Printf("os.Remove(%s): %s\n", filename, err)
@@ -94,7 +98,7 @@ func main() {
log.SetFlags(log.Lshortfile)
workdir := "."
- opts, optind, err := getopt.Getopts(os.Args, "e:d:")
+ opts, optind, err := getopt.Getopts(os.Args, "e:d:n")
if err != nil {
log.Fatal(err)
}
@@ -104,6 +108,8 @@ func main() {
append(excludes, opt.Value)
case 'd':
workdir = opt.Value
+ case 'n':
+ noop = true
default:
usage()
os.Exit(1)