Newer
Older
"github.com/tmrts/tmplt/pkg/template"
"github.com/tmrts/tmplt/pkg/tmplt"
"github.com/tmrts/tmplt/pkg/util/exit"
"github.com/tmrts/tmplt/pkg/util/validate"
func TemplateInRegistry(name string) (bool, error) {
names, err := ListTemplates()
if err != nil {
return false, err
}
_, ok := names[name]
return ok, nil
}
// TODO add --use-cache flag to execute a template from previous answers to prompts
Short: "Execute a project template in the given directory",
Run: func(c *cli.Command, args []string) {
MustValidateArgs(args, []validate.Argument{
{"template-name", validate.UnixPath},
{"target-dir", validate.UnixPath},
if ok, err := TemplateInRegistry(tmplName); err != nil {
exit.Fatal(fmt.Errorf("use: %s", err))
} else if !ok {
exit.Fatal(fmt.Errorf("Template %q couldn't be found in the template registry", tmplName))
}
}
tmpl, err := template.Get(tmplPath)
if shouldUseDefaults := GetBoolFlag(c, "use-defaults"); shouldUseDefaults {
tmpl.UseDefaultValues()
}
// Deletes the target dir if execute transaction fails
exit.OK("Successfully executed the project template %v in %v", tmplName, targetDir)