Skip to content

Commit 02fb807

Browse files
authored
Merge pull request #145 from tijn/add-env-flag
Add an --env flag to specify which env files to load
2 parents b181818 + c7abdac commit 02fb807

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ var exitOnStop = flag.Bool("exit-on-stop", true, "Exit goreman if all subprocess
102102
// show timestamp in log
103103
var logTime = flag.Bool("logtime", true, "show timestamp in log")
104104

105+
var envFileOption = flag.String("env", ".env", "Environment files to load, comma separated")
106+
105107
var maxProcNameLength = 0
106108

107109
var re = regexp.MustCompile(`\$([a-zA-Z_][a-zA-Z0-9_]*)`)
@@ -113,6 +115,7 @@ type config struct {
113115
BaseDir string `yaml:"basedir"`
114116
BasePort uint `yaml:"baseport"`
115117
Args []string
118+
EnvFiles []string
116119
// If true, exit the supervisor process if a subprocess exits with an error.
117120
ExitOnError bool `yaml:"exit_on_error"`
118121
}
@@ -129,6 +132,7 @@ func readConfig() *config {
129132
cfg.Port = *port
130133
cfg.BaseDir = *basedir
131134
cfg.BasePort = *baseport
135+
cfg.EnvFiles = strings.FieldsFunc(*envFileOption, func(char rune) bool { return char == ',' })
132136
cfg.ExitOnError = *exitOnError
133137
cfg.Args = flag.Args()
134138

@@ -270,7 +274,9 @@ func start(ctx context.Context, sig <-chan os.Signal, cfg *config) error {
270274
procs = tmp
271275
mu.Unlock()
272276
}
273-
godotenv.Load()
277+
if len(cfg.EnvFiles) > 0 {
278+
godotenv.Load(cfg.EnvFiles...)
279+
}
274280
rpcChan := make(chan *rpcMessage, 10)
275281
if *startRPCServer {
276282
go startServer(ctx, rpcChan, cfg.Port)

0 commit comments

Comments
 (0)