From 81ed06ea016f15b2b93c5c06097993754d858625 Mon Sep 17 00:00:00 2001 From: wangle <285273592@qq.com> Date: Fri, 11 Sep 2020 01:03:44 +0800 Subject: [PATCH] get template from git when run 'bee pro toml' if template dose not exit --- internal/app/module/beegopro/container.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/app/module/beegopro/container.go b/internal/app/module/beegopro/container.go index cbeb9b6..7f99cfb 100644 --- a/internal/app/module/beegopro/container.go +++ b/internal/app/module/beegopro/container.go @@ -67,6 +67,9 @@ func (c *Container) InitToml() { beeLogger.Log.Fatalf("file beegopro.toml already exists") } sourceFile := c.UserOption.GitLocalPath + "/beegopro.toml" + if !utils.IsExist(c.UserOption.GitLocalPath) { + c.getTemplateFromGit() + } input, err := ioutil.ReadFile(sourceFile) if err != nil { beeLogger.Log.Fatalf("read beegopro.toml file err, %s", err.Error()) @@ -80,6 +83,14 @@ func (c *Container) InitToml() { beeLogger.Log.Success("Successfully created file beegopro.toml") } +func (c *Container) getTemplateFromGit() { + err := git.CloneORPullRepo(c.UserOption.GitRemotePath, c.UserOption.GitLocalPath) + if err != nil { + beeLogger.Log.Fatalf("beego pro git clone or pull repo error, err: %s", err) + return + } + c.Timestamp.GitCacheLastRefresh = c.GenerateTimeUnix +} func (c *Container) initUserOption() { if !utils.IsExist(c.BeegoProFile) { beeLogger.Log.Fatalf("beego pro config is not exist, beego json path: %s", c.BeegoProFile) @@ -124,12 +135,7 @@ func (c *Container) initUserOption() { func (c *Container) initTemplateOption() { if c.UserOption.EnableGitPull && (c.GenerateTimeUnix-c.Timestamp.GitCacheLastRefresh > c.UserOption.RefreshGitTime) { - err := git.CloneORPullRepo(c.UserOption.GitRemotePath, c.UserOption.GitLocalPath) - if err != nil { - beeLogger.Log.Fatalf("beego pro git clone or pull repo error, err: %s", err) - return - } - c.Timestamp.GitCacheLastRefresh = c.GenerateTimeUnix + c.getTemplateFromGit() } tree, err := toml.LoadFile(c.UserOption.GitLocalPath + "/" + c.UserOption.ProType + "/bee.toml")