Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: key make support custom env path #237

Merged
merged 5 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions auth/console/jwt_secret_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/support"
"github.com/goravel/framework/support/str"
)

Expand Down Expand Up @@ -77,14 +78,14 @@ func (receiver *JwtSecretCommand) setSecretInEnvironmentFile(key string) error {

// writeNewEnvironmentFileWith Write a new environment file with the given key.
func (receiver *JwtSecretCommand) writeNewEnvironmentFileWith(key string) error {
content, err := os.ReadFile(".env")
content, err := os.ReadFile(support.EnvPath)
if err != nil {
return err
}

newContent := strings.Replace(string(content), "JWT_SECRET="+receiver.config.GetString("jwt.secret"), "JWT_SECRET="+key, 1)

err = os.WriteFile(".env", []byte(newContent), 0644)
err = os.WriteFile(support.EnvPath, []byte(newContent), 0644)
if err != nil {
return err
}
devhaozi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 1 addition & 4 deletions config/service_provider.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package config

import (
"flag"

"github.com/goravel/framework/contracts/foundation"
"github.com/goravel/framework/support"
)
Expand All @@ -18,8 +16,7 @@ func (config *ServiceProvider) Register(app foundation.Application) {
testEnv := ".env"
env = &testEnv
} else {
env = flag.String("env", ".env", "custom .env path")
flag.Parse()
env = &support.EnvPath
}

app.Singleton(Binding, func(app foundation.Application) (any, error) {
devhaozi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 3 additions & 2 deletions console/console/key_generate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/goravel/framework/contracts/config"
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/support"
"github.com/goravel/framework/support/str"
)

Expand Down Expand Up @@ -82,14 +83,14 @@ func (receiver *KeyGenerateCommand) generateRandomKey() string {

// writeNewEnvironmentFileWith Write a new environment file with the given key.
func (receiver *KeyGenerateCommand) writeNewEnvironmentFileWith(key string) error {
content, err := os.ReadFile(".env")
content, err := os.ReadFile(support.EnvPath)
if err != nil {
return err
}

newContent := strings.Replace(string(content), "APP_KEY="+receiver.config.GetString("app.key"), "APP_KEY="+key, 1)

err = os.WriteFile(".env", []byte(newContent), 0644)
err = os.WriteFile(support.EnvPath, []byte(newContent), 0644)
if err != nil {
return err
}
devhaozi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 5 additions & 0 deletions foundation/application.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package foundation

import (
"flag"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -178,6 +179,10 @@ func setEnv() {
support.Env = support.EnvArtisan
}
}

env := flag.String("env", ".env", "custom .env path")
flag.Parse()
support.EnvPath = *env
devhaozi marked this conversation as resolved.
Show resolved Hide resolved
}

func setRootPath() {
devhaozi marked this conversation as resolved.
Show resolved Hide resolved
devhaozi marked this conversation as resolved.
Show resolved Hide resolved
devhaozi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
1 change: 1 addition & 0 deletions support/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ const (

var (
Env = EnvRuntime
EnvPath string
RootPath string
)
devhaozi marked this conversation as resolved.
Show resolved Hide resolved
devhaozi marked this conversation as resolved.
Show resolved Hide resolved
Loading