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())) diff --git a/cmd/root.go b/cmd/root.go index fc40b6f0..8c82169e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -105,42 +105,25 @@ 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() } }