Initial pass for true and false conditionals for tasks
This commit is contained in:
parent
4bda542bd5
commit
29f25892d8
27
command.go
27
command.go
@ -61,7 +61,7 @@ func findCmdDeps(params []string, conf *config) []string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processCmdMacro(macroName string, args []string, conf *config) error {
|
func processCmdMacro(macroName string, args []string, interact bool, conf *config) error {
|
||||||
m, mn := findCmdMacro(macroName, conf)
|
m, mn := findCmdMacro(macroName, conf)
|
||||||
if m == nil {
|
if m == nil {
|
||||||
return fmt.Errorf("macro or variant not found: %s", macroName)
|
return fmt.Errorf("macro or variant not found: %s", macroName)
|
||||||
@ -75,10 +75,10 @@ func processCmdMacro(macroName string, args []string, conf *config) error {
|
|||||||
log.Printf("expanding macro: %s", mn)
|
log.Printf("expanding macro: %s", mn)
|
||||||
}
|
}
|
||||||
|
|
||||||
return processCmd(margs, conf)
|
return processCmd(margs, interact, conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func processCmd(params []string, conf *config) error {
|
func processCmd(params []string, interact bool, conf *config) error {
|
||||||
args := appendExpEnv(nil, params)
|
args := appendExpEnv(nil, params)
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return fmt.Errorf("invalid command statement")
|
return fmt.Errorf("invalid command statement")
|
||||||
@ -91,19 +91,28 @@ func processCmd(params []string, conf *config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(cmdName, "@") {
|
if strings.HasPrefix(cmdName, "@") {
|
||||||
return processCmdMacro(cmdName, cmdArgs, conf)
|
return processCmdMacro(cmdName, cmdArgs, interact, conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.flags&flagVerbose != 0 {
|
if conf.flags&flagVerbose != 0 {
|
||||||
log.Printf("executing command: %s %s", cmdName, strings.Join(cmdArgs, " "))
|
log.Printf("executing command: %s %s", cmdName, strings.Join(cmdArgs, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
return try(func() error {
|
exec := func() error {
|
||||||
cmd := exec.Command(cmdName, cmdArgs...)
|
cmd := exec.Command(cmdName, cmdArgs...)
|
||||||
cmd.Dir = conf.dstDir
|
cmd.Dir = conf.dstDir
|
||||||
cmd.Stderr = os.Stderr
|
if interact {
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
}
|
||||||
|
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if interact {
|
||||||
|
return try(exec)
|
||||||
|
}
|
||||||
|
|
||||||
|
return exec()
|
||||||
}
|
}
|
||||||
|
33
task.go
33
task.go
@ -28,10 +28,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type task struct {
|
type task struct {
|
||||||
Deps []string
|
Deps []string
|
||||||
Links [][]string
|
Links [][]string
|
||||||
Cmds [][]string
|
Cmds [][]string
|
||||||
Envs [][]string
|
Envs [][]string
|
||||||
|
IfTrue [][]string
|
||||||
|
IfFalse [][]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *task) deps(conf *config) []string {
|
func (t *task) deps(conf *config) []string {
|
||||||
@ -60,10 +62,27 @@ func (t *task) process(conf *config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if conf.flags&flagNoCmds == 0 {
|
if conf.flags&flagNoCmds == 0 {
|
||||||
for _, currCmd := range t.Cmds {
|
CmdLoop:
|
||||||
if err := processCmd(currCmd, conf); err != nil {
|
for {
|
||||||
return err
|
for _, currCnd := range t.IfTrue {
|
||||||
|
if err := processCmd(currCnd, false, conf); err != nil {
|
||||||
|
break CmdLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, currCnd := range t.IfFalse {
|
||||||
|
if err := processCmd(currCnd, false, conf); err == nil {
|
||||||
|
break CmdLoop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, currCmd := range t.Cmds {
|
||||||
|
if err := processCmd(currCmd, true, conf); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user