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

Set config file path via PFTQCONFIG env var #19

Merged
merged 2 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,11 @@ $ pftaskqueue print-default-config > ~/.pftaskqueue.yaml
$ PFTQ_REDIS_ADDR=... pftaskqueue ...
```

### Config files
### Config file

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

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

Expand Down
5 changes: 4 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func init() {

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

// Log setting
Expand Down Expand Up @@ -239,6 +239,9 @@ func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else if env, ok := os.LookupEnv("PFTQCONFIG"); ok {
// Use config file from env var.
viper.SetConfigFile(env)
} else {
// Find home directory.
home, err := homedir.Dir()
Expand Down