mirror of
https://github.com/wahyd4/forego.git
synced 2026-08-08 21:01:01 +10:00
Support multiple environment files on forego run
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/subosito/gotenv"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
@@ -11,6 +12,22 @@ var envEntryRegexp = regexp.MustCompile("^([A-Za-z_0-9]+)=(.*)$")
|
||||
|
||||
type Env map[string]string
|
||||
|
||||
type envFiles []string
|
||||
|
||||
func (e *envFiles) String() string {
|
||||
return fmt.Sprintf("%s", *e)
|
||||
}
|
||||
|
||||
func (e *envFiles) Set(value string) error {
|
||||
*e = append(*e, fullPath(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
func fullPath(file string) string {
|
||||
root := filepath.Dir(".")
|
||||
return filepath.Join(root, file)
|
||||
}
|
||||
|
||||
func loadEnvs(files []string) (Env, error) {
|
||||
if len(files) == 0 {
|
||||
env, err := ReadEnv(fullPath(".env"))
|
||||
|
||||
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -19,8 +18,10 @@ Examples:
|
||||
`,
|
||||
}
|
||||
|
||||
var runEnvs envFiles
|
||||
|
||||
func init() {
|
||||
cmdRun.Flag.StringVar(&flagEnv, "e", ".env", "env")
|
||||
cmdRun.Flag.Var(&runEnvs, "e", "env")
|
||||
}
|
||||
|
||||
func runRun(cmd *Command, args []string) {
|
||||
@@ -32,11 +33,8 @@ func runRun(cmd *Command, args []string) {
|
||||
if err != nil {
|
||||
handleError(err)
|
||||
}
|
||||
if flagEnv == "" {
|
||||
flagEnv = filepath.Join(workDir, ".env")
|
||||
}
|
||||
|
||||
env, err := ReadEnv(flagEnv)
|
||||
env, err := loadEnvs(runEnvs)
|
||||
handleError(err)
|
||||
|
||||
const interactive = true
|
||||
|
||||
@@ -14,17 +14,6 @@ import (
|
||||
|
||||
const shutdownGraceTime = 3 * time.Second
|
||||
|
||||
type envFiles []string
|
||||
|
||||
func (e *envFiles) String() string {
|
||||
return fmt.Sprintf("%s", *e)
|
||||
}
|
||||
|
||||
func (e *envFiles) Set(value string) error {
|
||||
*e = append(*e, fullPath(value))
|
||||
return nil
|
||||
}
|
||||
|
||||
var flagPort int
|
||||
var flagConcurrency string
|
||||
var flagRestart bool
|
||||
@@ -191,11 +180,6 @@ func (f *Forego) startProcess(idx, procNum int, proc ProcfileEntry, env Env, of
|
||||
}()
|
||||
}
|
||||
|
||||
func fullPath(file string) string {
|
||||
root := filepath.Dir(".")
|
||||
return filepath.Join(root, file)
|
||||
}
|
||||
|
||||
func runStart(cmd *Command, args []string) {
|
||||
pf, err := ReadProcfile(flagProcfile)
|
||||
handleError(err)
|
||||
|
||||
Reference in New Issue
Block a user