From 70b73b2974af94c657a71473b29e4718a777ab62 Mon Sep 17 00:00:00 2001 From: k0a1a Date: Thu, 24 Feb 2022 22:24:52 +0800 Subject: [PATCH 1/3] fix: init config failed --- cmd/init.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/init.go b/cmd/init.go index 6bcb5e9e..e160524d 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -301,7 +301,8 @@ func makeFile(name string, source string) { makeFileContent(name, []byte(source)) } -func makeFileContent(filename string, content []byte) { +func makeFileContent(name string, content []byte) { + filename := filepath.Join(config.Conf.Root, name) err := os.WriteFile(filename, content, 0644) if err != nil { fmt.Println(color.RedString(L("Fatal: %s"), err.Error())) From 73295cfabdbbbe32f1fe3fb1ed7ccbfabaab7901 Mon Sep 17 00:00:00 2001 From: k0a1a Date: Fri, 25 Feb 2022 10:39:09 +0800 Subject: [PATCH 2/3] fix: init config failed --- cmd/root.go | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index fc40b6f0..2bbc9d7b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -105,42 +105,26 @@ func Execute() { } } -// Boot 设定配置 (这个逻辑有 BUG ) +// Boot 设定配置 func Boot() { - - if envFile == "" && appPath != "" { - root, err := filepath.Abs(appPath) + root := config.Conf.Root + if appPath != "" { + r, err := filepath.Abs(appPath) if err != nil { exception.New("Root error %s", 500, err.Error()).Throw() } + root = r + } + if envFile != "" { + config.Conf = config.LoadFrom(envFile) + } else { config.Conf = config.LoadFrom(filepath.Join(root, ".env")) - config.Conf.Root = root - if config.Conf.Mode == "production" { - config.Production() - } else if config.Conf.Mode == "development" { - config.Development() - } - - return } - if envFile != "" && appPath == "" { // 指定环境变量文件 - // config.SetEnvFile(envFile) - config.Conf = config.LoadFrom(envFile) - } - - if envFile != "" && appPath != "" { - root, err := filepath.Abs(appPath) - if err != nil { - exception.New("Root error %s", 500, err.Error()).Throw() - } - config.Conf = config.LoadFrom(envFile) - config.Conf.Root = root - if config.Conf.Mode == "production" { - config.Production() - } else if config.Conf.Mode == "development" { - config.Development() - } - + if config.Conf.Mode == "production" { + config.Production() + } else if config.Conf.Mode == "development" { + config.Development() } + fmt.Println(root) } From 3c8385bb6ea7036f1cc28476f2d4aca986c2d1e7 Mon Sep 17 00:00:00 2001 From: k0a1a Date: Fri, 25 Feb 2022 22:44:36 +0800 Subject: [PATCH 3/3] fix: init config failed --- cmd/root.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 2bbc9d7b..8c82169e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -126,5 +126,4 @@ func Boot() { } else if config.Conf.Mode == "development" { config.Development() } - fmt.Println(root) }