Add support for environment variable expansion in dependencies

This commit is contained in:
Lucas Bremgartner 2017-06-30 12:01:37 +02:00
parent 87f1a4e15c
commit e2474969bd
2 changed files with 7 additions and 5 deletions

View File

@ -248,11 +248,11 @@ itself) in the `links` block; you can read more about how to use environment var
### Environment Variables ### ### Environment Variables ###
Homemaker supports the expansion of environment variables for both command and link blocks. This is a good way of Homemaker supports the expansion of environment variables for both command and link blocks as well as for dependencies.
avoiding having to hard code absolute paths into your configuration file. To reference an environment variable simply This is a good way of avoiding having to hard code absolute paths into your configuration file. To reference an
use `${ENVVAR}` or `$ENVVAR`, where `ENVVAR` is the variable name (notice the similarity to normal shell variable environment variable simply use `${ENVVAR}` or `$ENVVAR`, where `ENVVAR` is the variable name (notice the similarity
expansion). In addition to being able to reference all of the environment variables defined on your system, Homemaker to normal shell variable expansion). In addition to being able to reference all of the environment variables defined
defines a couple of extra ones for ease of use: on your system, Homemaker defines a couple of extra ones for ease of use:
* `HM_CONFIG` * `HM_CONFIG`

View File

@ -25,6 +25,7 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"os"
) )
type task struct { type task struct {
@ -52,6 +53,7 @@ func (t *task) deps(conf *config) []string {
func (t *task) process(conf *config) error { func (t *task) process(conf *config) error {
for _, currTask := range t.deps(conf) { for _, currTask := range t.deps(conf) {
currTask = os.ExpandEnv(currTask)
if err := processTask(currTask, conf); err != nil { if err := processTask(currTask, conf); err != nil {
return err return err
} }