Merge pull request #19 from thlz998/thlz998/cmd-init

fix: init config failed
This commit is contained in:
Max 2022-02-25 23:08:44 +08:00 committed by GitHub
commit d6f01fea96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 31 deletions

View file

@ -301,7 +301,8 @@ func makeFile(name string, source string) {
makeFileContent(name, []byte(source)) 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) err := os.WriteFile(filename, content, 0644)
if err != nil { if err != nil {
fmt.Println(color.RedString(L("Fatal: %s"), err.Error())) fmt.Println(color.RedString(L("Fatal: %s"), err.Error()))

View file

@ -105,42 +105,25 @@ func Execute() {
} }
} }
// Boot 设定配置 (这个逻辑有 BUG ) // Boot 设定配置
func Boot() { func Boot() {
root := config.Conf.Root
if envFile == "" && appPath != "" { if appPath != "" {
root, err := filepath.Abs(appPath) r, err := filepath.Abs(appPath)
if err != nil { if err != nil {
exception.New("Root error %s", 500, err.Error()).Throw() 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 = 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 == "" { // 指定环境变量文件 if config.Conf.Mode == "production" {
// config.SetEnvFile(envFile) config.Production()
config.Conf = config.LoadFrom(envFile) } else if config.Conf.Mode == "development" {
} config.Development()
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()
}
} }
} }