More work on macros

This commit is contained in:
Alex Yatskov 2015-07-20 20:29:05 +09:00
parent 4fc1dc0e9d
commit 2a10a02784
3 changed files with 12 additions and 9 deletions

View File

@ -38,12 +38,10 @@ type macro struct {
func processCmd(params []string, dir string, conf *config, flags int) error { func processCmd(params []string, dir string, conf *config, flags int) error {
args := appendExpEnv(nil, params) args := appendExpEnv(nil, params)
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("command element is invalid") return fmt.Errorf("invalid command statement")
} }
cmdName := args[0] cmdName := args[0]
var cmdArgs []string
if strings.HasPrefix(cmdName, "@") { if strings.HasPrefix(cmdName, "@") {
macroName := strings.TrimPrefix(cmdName, "@") macroName := strings.TrimPrefix(cmdName, "@")
@ -52,16 +50,21 @@ func processCmd(params []string, dir string, conf *config, flags int) error {
return fmt.Errorf("macro not found %s", macroName) return fmt.Errorf("macro not found %s", macroName)
} }
cmdArgs = appendExpEnv(cmdArgs, m.Prefix) margs := appendExpEnv(nil, m.Prefix)
if len(args) > 1 { if len(args) > 1 {
cmdArgs = appendExpEnv(cmdArgs, args[1:]) margs = appendExpEnv(margs, args[1:])
} }
cmdArgs = appendExpEnv(cmdArgs, m.Suffix) margs = appendExpEnv(margs, m.Suffix)
if flags&flagVerbose == flagVerbose { if flags&flagVerbose == flagVerbose {
log.Printf("using macro %s", macroName) log.Printf("using macro %s", macroName)
} }
} else if len(args) > 1 {
return processCmd(margs, dir, conf, flags)
}
var cmdArgs []string
if len(args) > 1 {
cmdArgs = args[1:] cmdArgs = args[1:]
} }

View File

@ -35,7 +35,7 @@ func processEnv(env []string, flags int) error {
var value string var value string
switch { switch {
case len(args) == 0: case len(args) == 0:
return fmt.Errorf("enviornment element is invalid") return fmt.Errorf("invalid environment statement")
case len(args) == 1: case len(args) == 1:
if flags&flagVerbose == flagVerbose { if flags&flagVerbose == flagVerbose {
log.Printf("unsetting variable %s", args[0]) log.Printf("unsetting variable %s", args[0])

View File

@ -73,7 +73,7 @@ func createPath(loc string, flags int, mode os.FileMode) error {
func parseLink(params []string) (srcPath, dstPath string, mode os.FileMode, err error) { func parseLink(params []string) (srcPath, dstPath string, mode os.FileMode, err error) {
length := len(params) length := len(params)
if length < 1 || length > 3 { if length < 1 || length > 3 {
err = fmt.Errorf("link element is invalid") err = fmt.Errorf("invalid link statement")
return return
} }