diff --git a/RunSettings.go b/RunSettings.go index c1330fb..9ef0f72 100644 --- a/RunSettings.go +++ b/RunSettings.go @@ -25,6 +25,7 @@ type RunSettings struct { addRegistry bool showRegistry bool forceGenerate GenerateMode + blankParameters bool flagList bool } @@ -44,6 +45,7 @@ var FLAGS = []string{ "-l", "-f", "-w", + "-b", "-bu", "-bp", "-flags", @@ -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() diff --git a/main.go b/main.go index 54d3fb8..2968cde 100644 --- a/main.go +++ b/main.go @@ -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 { @@ -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) {