Support multiple environment files on forego run

This commit is contained in:
Nicolás Hock Isaza
2014-12-22 19:41:47 -05:00
parent 656dbf434d
commit 294ed6c9ec
3 changed files with 21 additions and 22 deletions
+17
View File
@@ -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"))
+4 -6
View File
@@ -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
-16
View File
@@ -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)