-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
84 lines (75 loc) · 1.9 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* @Description: 填写描述
* @Author: WangXinyong/TaceyWong
* @Date: 2020-09-25 13:51:46
* @LastEditors: WangXinyong/TaceyWong
* @LastEditTime: 2020-09-25 15:03:57
* @FilePath: /starter/utils.go
*/
package starter
import (
"fmt"
"log"
"os"
)
func RmTree(dirPath string) {
os.RemoveAll(dirPath)
}
func MakeSurePathExist(path string) bool {
log.Printf("Making sure path exists:%s", path)
if os.MkdirAll(path, os.ModePerm) != nil {
log.Printf("%s has existed", path)
return false
}
log.Printf("Created directory at: %s", path)
return true
}
func WorkIn(dirname string) {
}
// MakeExecutable Make `scriptPath` executable
//
// param scriptPath: The file to change mode
func MakeExecutable(scriptPath string) {
// stats, err := os.Stat(scriptPath)
// if err != nil {
// log.Fatal(err)
// }
// os.Chmod(scriptPath, stats.Mode()|filemode.Executable) //100755
}
// PromptAndDelete Ask user if it's okay to delete the previously-downloaded file/directory.
//
// If yes, delete it. If no, checks to see if the old version should be
// reused. If yes, it's reused; otherwise, Cookiecutter exits.
//
// :param path: Previously downloaded zipfile.
// :param noInput: Suppress prompt to delete repo and just delete it.
// :return: True if the content was deleted
func PromptAndDelete(path string, noInput bool) bool {
okToDelete := false
if noInput {
okToDelete = true
} else {
question := fmt.Sprintf("You've downloaded %s before. Is it okay to delete and re-download it?", path)
ReadUserYesNo(&okToDelete, question, true)
}
if okToDelete {
info, err := os.Stat(path)
if os.IsNotExist(err) {
log.Fatal("File does not exist.")
}
if info.IsDir() {
RmTree(path)
} else {
os.Remove(path)
}
} else {
okToReuse := false
question := "Do you want to re-use the existing version?"
ReadUserYesNo(&okToReuse, question, true)
if okToReuse {
return false
}
os.Exit(0)
}
return false
}