Skip to content

Commit 6107cd9

Browse files
committed
Implemented warning if destination directory exists
1 parent 5566662 commit 6107cd9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

RunSettings.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type RunSettings struct {
2020
inspectionRun bool
2121
addRegistry bool
2222
showRegistry bool
23+
forceGenerate bool
2324
}
2425

2526
/*
@@ -35,6 +36,7 @@ func FindRunSettings() (RunSettings, error) {
3536
flag.BoolVar(&ret.inspectionRun, "i", false, "Whether or not to show a list of available parameters for the skeleton")
3637
flag.BoolVar(&ret.addRegistry, "a", false, "Whether or not to register the template at the given path")
3738
flag.BoolVar(&ret.showRegistry, "l", false, "Whether or not to show a list of all available registered templates")
39+
flag.BoolVar(&ret.forceGenerate, "f", false, "Whether or not to overwrite existing files during generation")
3840
flag.Parse()
3941

4042
ret.skeletonPath = flag.Arg(0)

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ func createProject(settings RunSettings, registry *TemplateRegistry) {
9999
return
100100
}
101101

102+
// if force wasn't specified, check to see if the destination already exists
103+
if(!settings.forceGenerate) {
104+
105+
_, err = os.Stat(settings.targetPath)
106+
if(err == nil) {
107+
fmt.Println("Destination path already exists, and no '-f' option was specified. Use '-f' to overwrite existing files.")
108+
return
109+
}
110+
}
111+
102112
// generate a project
103113
err = project.GenerateAt(settings.targetPath, settings.parameters)
104114
if err != nil {

0 commit comments

Comments
 (0)