Skip to content

Commit 926adbd

Browse files
authored
Merge pull request #19 from ordovicia/config-path-from-env-var
Set config file path via PFTQCONFIG env var
2 parents 0723025 + c698823 commit 926adbd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,11 @@ $ pftaskqueue print-default-config > ~/.pftaskqueue.yaml
710710
$ PFTQ_REDIS_ADDR=... pftaskqueue ...
711711
```
712712

713-
### Config files
713+
### Config file
714714

715-
`pftaskqueue` automatically reads `${HOME}/.pftaskqueue.yaml` if exists. Or, you can also set any configuration path with `--config=${CONFIG_FILE_PATH}` flag or both.
715+
`pftaskqueue` automatically reads `${HOME}/.pftaskqueue.yaml` if exists.
716+
Or, you can also set any configuration path with `--config=${CONFIG_FILE_PATH}` flag or `PFTQCONFIG` environment variable.
717+
`--config` flag is prioritized over `PFTQCONFIG` environment variable.
716718

717719
To generate config file with default values, please run `print-default-config` command.
718720

cmd/root.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func init() {
144144

145145
rootCmd.SetVersionTemplate(VersionString())
146146
flag := rootCmd.PersistentFlags()
147-
flag.StringVar(&cfgFile, "config", "", "config file path. [default = $HOME/.pftaskqueue.yaml]")
147+
flag.StringVar(&cfgFile, "config", "", "config file path. [default = $PFTQCONFIG or $HOME/.pftaskqueue.yaml]")
148148
flag.BoolVar(&displayOpts, "display-options", false, "display loaded config values at startup")
149149

150150
// Log setting
@@ -239,6 +239,9 @@ func initConfig() {
239239
if cfgFile != "" {
240240
// Use config file from the flag.
241241
viper.SetConfigFile(cfgFile)
242+
} else if env, ok := os.LookupEnv("PFTQCONFIG"); ok {
243+
// Use config file from env var.
244+
viper.SetConfigFile(env)
242245
} else {
243246
// Find home directory.
244247
home, err := homedir.Dir()

0 commit comments

Comments
 (0)