1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

beam/examples/beamsh: scripts can be passed as filenames

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-03-27 15:54:18 -07:00
parent 222fc87ade
commit e1c8dbba97
2 changed files with 49 additions and 21 deletions

View file

@ -25,34 +25,54 @@ func main() {
Fatal(err) Fatal(err)
} }
defer devnull.Close() defer devnull.Close()
if term.IsTerminal(0) { if len(os.Args) == 1 {
input := bufio.NewScanner(os.Stdin) if term.IsTerminal(0) {
for { input := bufio.NewScanner(os.Stdin)
os.Stdout.Write([]byte("beamsh> ")) for {
if !input.Scan() { os.Stdout.Write([]byte("beamsh> "))
break if !input.Scan() {
} break
line := input.Text() }
if len(line) != 0 { line := input.Text()
cmd, err := dockerscript.Parse(strings.NewReader(line)) if len(line) != 0 {
if err != nil { cmd, err := dockerscript.Parse(strings.NewReader(line))
fmt.Fprintf(os.Stderr, "error: %v\n", err) if err != nil {
continue fmt.Fprintf(os.Stderr, "error: %v\n", err)
continue
}
if err := executeScript(devnull, cmd); err != nil {
Fatal(err)
}
}
if err := input.Err(); err == io.EOF {
break
} else if err != nil {
Fatal(err)
} }
executeScript(devnull, cmd)
} }
if err := input.Err(); err == io.EOF { } else {
break script, err := dockerscript.Parse(os.Stdin)
} else if err != nil { if err != nil {
Fatal("parse error: %v\n", err)
}
if err := executeScript(devnull, script); err != nil {
Fatal(err) Fatal(err)
} }
} }
} else { } else {
script, err := dockerscript.Parse(os.Stdin) for _, scriptpath := range os.Args[1:] {
if err != nil { f, err := os.Open(scriptpath)
Fatal("parse error: %v\n", err) if err != nil {
Fatal(err)
}
script, err := dockerscript.Parse(f)
if err != nil {
Fatal("parse error: %v\n", err)
}
if err := executeScript(devnull, script); err != nil {
Fatal(err)
}
} }
executeScript(devnull, script)
} }
} }

View file

@ -0,0 +1,8 @@
#!/usr/bin/env beamsh
print {
trace {
emit hello
emit world
}
}