Skip to content

Commit

Permalink
Implemented warning if destination directory exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Knetic committed Sep 19, 2015
1 parent 5566662 commit 6107cd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RunSettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type RunSettings struct {
inspectionRun bool
addRegistry bool
showRegistry bool
forceGenerate bool
}

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

ret.skeletonPath = flag.Arg(0)
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ func createProject(settings RunSettings, registry *TemplateRegistry) {
return
}

// if force wasn't specified, check to see if the destination already exists
if(!settings.forceGenerate) {

_, err = os.Stat(settings.targetPath)
if(err == nil) {
fmt.Println("Destination path already exists, and no '-f' option was specified. Use '-f' to overwrite existing files.")
return
}
}

// generate a project
err = project.GenerateAt(settings.targetPath, settings.parameters)
if err != nil {
Expand Down

0 comments on commit 6107cd9

Please sign in to comment.