MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / askDeleteFile

Function askDeleteFile

cmd/cql/internal/generate.go:86–112  ·  view source on GitHub ↗
(file string)

Source from the content-addressed store, hash-verified

84}
85
86func askDeleteFile(file string) {
87 if fileinfo, err := os.Stat(file); err == nil {
88 if fileinfo.IsDir() {
89 return
90 }
91 reader := bufio.NewReader(os.Stdin)
92 fmt.Printf("\"%s\" already exists. \nDo you want to delete it? (y or n, press Enter for default n):\n",
93 file)
94 t, err := reader.ReadString('\n')
95 t = strings.Trim(t, "\n")
96 if err != nil {
97 ConsoleLog.WithError(err).Error("unexpected error")
98 SetExitStatus(1)
99 Exit()
100 }
101 if strings.EqualFold(t, "y") || strings.EqualFold(t, "yes") {
102 err = os.Remove(file)
103 if err != nil {
104 ConsoleLog.WithError(err).Error("unexpected error")
105 SetExitStatus(1)
106 Exit()
107 }
108 } else {
109 Exit()
110 }
111 }
112}
113
114func runGenerate(cmd *Command, args []string) {
115 commonFlagsInit(cmd)

Callers 1

runGenerateFunction · 0.85

Calls 7

SetExitStatusFunction · 0.85
ExitFunction · 0.85
StatMethod · 0.80
ErrorMethod · 0.80
WithErrorMethod · 0.80
PrintfMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected