beam/examples/beamsh: support for background commands with '&' terminator
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
086724e1a3
commit
529e741f08
2 changed files with 16 additions and 3 deletions
|
@ -136,9 +136,19 @@ func scriptString(script []*dockerscript.Command) string {
|
||||||
func executeScript(client *net.UnixConn, script []*dockerscript.Command) error {
|
func executeScript(client *net.UnixConn, script []*dockerscript.Command) error {
|
||||||
Debugf("executeScript(%s)\n", scriptString(script))
|
Debugf("executeScript(%s)\n", scriptString(script))
|
||||||
defer Debugf("executeScript(%s) DONE\n", scriptString(script))
|
defer Debugf("executeScript(%s) DONE\n", scriptString(script))
|
||||||
|
var background sync.WaitGroup
|
||||||
|
defer background.Wait()
|
||||||
for _, cmd := range script {
|
for _, cmd := range script {
|
||||||
if err := executeCommand(client, cmd); err != nil {
|
if cmd.Background {
|
||||||
return err
|
background.Add(1)
|
||||||
|
go func(client *net.UnixConn, cmd *dockerscript.Command) {
|
||||||
|
executeCommand(client, cmd)
|
||||||
|
background.Done()
|
||||||
|
}(client, cmd)
|
||||||
|
} else {
|
||||||
|
if err := executeCommand(client, cmd); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
type Command struct {
|
type Command struct {
|
||||||
Args []string
|
Args []string
|
||||||
Children []*Command
|
Children []*Command
|
||||||
|
Background bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Scanner struct {
|
type Scanner struct {
|
||||||
|
@ -72,7 +73,7 @@ func parseArgs(s *Scanner) ([]string, rune, error) {
|
||||||
return args, tok, nil
|
return args, tok, nil
|
||||||
}
|
}
|
||||||
if !s.commentLine {
|
if !s.commentLine {
|
||||||
if text == "{" || text == "}" || text == "\n" || text == "\r" || text == ";" {
|
if text == "{" || text == "}" || text == "\n" || text == "\r" || text == ";" || text == "&" {
|
||||||
return args, tok, nil
|
return args, tok, nil
|
||||||
}
|
}
|
||||||
args = append(args, text)
|
args = append(args, text)
|
||||||
|
@ -106,6 +107,8 @@ func parse(s *Scanner, opener string) (expr []*Command, err error) {
|
||||||
cmd.Children = children
|
cmd.Children = children
|
||||||
} else if afterArgs == "}" && opener != "{" {
|
} else if afterArgs == "}" && opener != "{" {
|
||||||
return nil, fmt.Errorf("unexpected end of block '}'")
|
return nil, fmt.Errorf("unexpected end of block '}'")
|
||||||
|
} else if afterArgs == "&" {
|
||||||
|
cmd.Background = true
|
||||||
}
|
}
|
||||||
if len(cmd.Args) > 0 || len(cmd.Children) > 0 {
|
if len(cmd.Args) > 0 || len(cmd.Children) > 0 {
|
||||||
expr = append(expr, cmd)
|
expr = append(expr, cmd)
|
||||||
|
|
Loading…
Add table
Reference in a new issue