diff --git a/command.go b/command.go index 2a1c4f5..7ce398d 100644 --- a/command.go +++ b/command.go @@ -32,19 +32,25 @@ import ( type command []string -func (c *command) process(dir string, flags int) error { - if len(*c) < 1 { +func (c command) expandEnv() { + for index, value := range c { + c[index] = os.ExpandEnv(value) + } +} + +func (c command) process(dir string, flags int) error { + if len(c) < 1 { return fmt.Errorf("command element is invalid") } - cmd := exec.Command((*c)[0], (*c)[1:]...) + cmd := exec.Command(c[0], c[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(c, " ")) } return cmd.Run() diff --git a/link.go b/link.go index 128e4d6..5c2fc05 100644 --- a/link.go +++ b/link.go @@ -72,32 +72,35 @@ func createPath(loc string, flags int, mode os.FileMode) error { return nil } -func (l *link) parse() (string, string, os.FileMode, error) { - length := len(*l) +func (l link) parse() (srcPath string, dstPath string, mode os.FileMode, err error) { + length := len(l) if length < 1 || length > 3 { - return "", "", 0, fmt.Errorf("link element is invalid") + err = fmt.Errorf("link element is invalid") + return } - dstPath := (*l)[0] - srcPath := dstPath - if length > 1 { - srcPath = (*l)[1] - } - - var mode os.FileMode = 0755 if length > 2 { - parsed, err := strconv.ParseUint((*l)[2], 0, 64) + var parsed uint64 + parsed, err = strconv.ParseUint(l[2], 0, 64) if err != nil { - return "", "", 0, err + return } mode = os.FileMode(parsed) + } else { + mode = 0755 } - return srcPath, dstPath, mode, nil + dstPath = os.ExpandEnv(l[0]) + srcPath = dstPath + if length > 1 { + srcPath = os.ExpandEnv(l[1]) + } + + return } -func (l *link) process(srcDir, dstDir string, flags int) error { +func (l link) process(srcDir, dstDir string, flags int) error { srcPath, dstPath, mode, err := l.parse() if err != nil { return err