Skip to content

Commit

Permalink
Changed behavior around incorrect/missing parameters to be more stric…
Browse files Browse the repository at this point in the history
…t, and not leave around a project that was (probably) not generated correctly
  • Loading branch information
Knetic committed Jun 10, 2016
1 parent 325d7b2 commit 89034fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions RunSettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type RunSettings struct {
addRegistry bool
showRegistry bool
forceGenerate GenerateMode
blankParameters bool

flagList bool
}
Expand All @@ -44,6 +45,7 @@ var FLAGS = []string{
"-l",
"-f",
"-w",
"-b",
"-bu",
"-bp",
"-flags",
Expand All @@ -67,6 +69,7 @@ func FindRunSettings() (RunSettings, error) {
flag.BoolVar(&ret.showRegistry, "l", false, "Whether or not to show a list of all available registered templates")
flag.BoolVar(&forceGenerate, "f", false, "Whether or not to overwrite existing files during generation")
flag.BoolVar(&forceDelete, "d", false, "Whether or not to delete every existing file in the output path first (only valid when -f is specified)")
flag.BoolVar(&ret.blankParameters, "b", false, "Whether or not to replace unspecified parameters with blank strings")
flag.BoolVar(&ret.flagList, "flags", false, "Whether or not to list the flags")
flag.Parse()

Expand Down
27 changes: 19 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,24 @@ func createProject(settings RunSettings, registry *TemplateRegistry) {
return
}

// if there's a post-generate script (and it's executable), call it.
err = executePostGenerate(project.rootDirectory, settings.targetPath)
if err != nil {
exitWith("Unable to complete post-generation script: %s\n", err, 1)
return
}

// if everything succeeded, but we had missing parameters, make a note of it to the user.
if project.missingParameters.Length() > 0 {
fmt.Printf("Project generated, but some parameters were not specified, and have been left blank:\n")

if(settings.blankParameters) {

// if blank parameters are allowed, print a message about how blank parameters were used.
fmt.Printf("Project generated, but some parameters were not specified, and have been left blank:\n")
} else {

// if blank parameters are not allowed, delete the generated project.
fmt.Printf("Project cannot be generated, some parameters were not specified:\n")
os.RemoveAll(settings.targetPath)
}

for _, value := range project.missingParameters.GetSlice() {
fmt.Println(value)
}
return
}

if project.incorrectParameters.Length() > 0 {
Expand All @@ -159,6 +163,13 @@ func createProject(settings RunSettings, registry *TemplateRegistry) {
fmt.Println(value)
}
}

// if there's a post-generate script (and it's executable), call it.
err = executePostGenerate(project.rootDirectory, settings.targetPath)
if err != nil {
exitWith("Unable to complete post-generation script: %s\n", err, 1)
return
}
}

func exitWith(message string, err error, code int) {
Expand Down

0 comments on commit 89034fd

Please sign in to comment.