From 57cee5f1e25082b34669225d2bd65090ea573e72 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Thu, 2 Jul 2015 17:47:41 +0900 Subject: [PATCH] Expand environment vars for commands --- command.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/command.go b/command.go index 7ce398d..b65f8b6 100644 --- a/command.go +++ b/command.go @@ -32,10 +32,13 @@ import ( type command []string -func (c command) expandEnv() { - for index, value := range c { - c[index] = os.ExpandEnv(value) +func (c command) expandEnv() []string { + var args []string + for _, value := range c { + args = append(args, os.ExpandEnv(value)) } + + return args } func (c command) process(dir string, flags int) error { @@ -43,14 +46,16 @@ func (c command) process(dir string, flags int) error { return fmt.Errorf("command element is invalid") } - cmd := exec.Command(c[0], c[1:]...) + args := c.expandEnv() + + cmd := exec.Command(args[0], args[1:]...) cmd.Dir = dir cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout cmd.Stdin = os.Stdin if flags&flagVerbose == flagVerbose { - log.Printf("executing command %s", strings.Join(c, " ")) + log.Printf("executing command %s", strings.Join(args, " ")) } return cmd.Run()