Skip to content

Commit 80ee5fb

Browse files
committed
add delete script
1 parent 3edc36c commit 80ee5fb

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

deleteBuild/deleteBuild

2.19 MB
Binary file not shown.

deleteBuild/main.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
_____ ______ __ ______ ______ ______
3+
/\ __-. /\ ___\ /\ \ /\ ___\ /\__ _\ /\ ___\
4+
\ \ \/\ \ \ \ __\ \ \ \____ \ \ __\ \/_/\ \/ \ \ __\
5+
\ \____- \ \_____\ \ \_____\ \ \_____\ \ \_\ \ \_____\
6+
\/____/ \/_____/ \/_____/ \/_____/ \/_/ \/_____/
7+
8+
*/
9+
package main
10+
11+
import (
12+
"fmt"
13+
"os"
14+
// aliasing library names
15+
flag "github.com/ogier/pflag"
16+
"path/filepath"
17+
"github.com/fatih/color"
18+
)
19+
20+
var debug bool
21+
var rootPath string
22+
var folderName string
23+
24+
func init() {
25+
flag.StringVarP(&rootPath, "path", "p", "./", "directory to start with")
26+
flag.StringVarP(&folderName, "name", "n", "build", "specific file name needs to be delete")
27+
flag.BoolVarP(&debug, "debug", "d", false, "Skip delele for debug")
28+
}
29+
30+
func printUsage(){
31+
color.Green("Delete build files recursively")
32+
color.Green("Usage: %s [options]\n", os.Args[0])
33+
fmt.Println("Options:")
34+
flag.PrintDefaults()
35+
os.Exit(1)
36+
}
37+
38+
func die(a interface{}, e error) {
39+
fmt.Println(a, e)
40+
os.Exit(1)
41+
}
42+
43+
func main() {
44+
flag.Parse()
45+
if flag.NFlag() == 0 {
46+
printUsage()
47+
}
48+
if _, err := os.Stat(rootPath); err != nil {
49+
die("directory does not exist", err)
50+
}
51+
fileList := []string{}
52+
filepath.Walk(rootPath, func(path string, info os.FileInfo, err error)error {
53+
if info.Name() == folderName {
54+
color.Green("Found %s", path)
55+
fileList = append(fileList, path)
56+
}
57+
return err
58+
})
59+
for _, file := range fileList {
60+
color.Yellow("Delete %s", file)
61+
if debug {
62+
continue
63+
}
64+
if e := os.RemoveAll(file); e != nil {
65+
color.Red("Remove failed %v", e)
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)