Configuration file environment variable expansion

This commit adds simple variable expansion using either `$FOO`
or `${FOO}` when evaluating the config file. This can be disabled
by any command by using the `-no-expand-env` flag.
This commit is contained in:
Ben Johnson
2021-04-16 09:28:01 -06:00
parent cefbcb0460
commit 04ae010378
8 changed files with 100 additions and 21 deletions

View File

@@ -17,7 +17,7 @@ type WALCommand struct{}
// Run executes the command.
func (c *WALCommand) Run(ctx context.Context, args []string) (err error) {
fs := flag.NewFlagSet("litestream-wal", flag.ContinueOnError)
configPath := registerConfigFlag(fs)
configPath, noExpandEnv := registerConfigFlag(fs)
replicaName := fs.String("replica", "", "replica name")
generation := fs.String("generation", "", "generation name")
fs.Usage = c.Usage
@@ -44,7 +44,7 @@ func (c *WALCommand) Run(ctx context.Context, args []string) (err error) {
}
// Load configuration.
config, err := ReadConfigFile(*configPath)
config, err := ReadConfigFile(*configPath, !*noExpandEnv)
if err != nil {
return err
}
@@ -118,6 +118,9 @@ Arguments:
Specifies the configuration file.
Defaults to %s
-no-expand-env
Disables environment variable expansion in configuration file.
-replica NAME
Optional, filter by a specific replica.