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:
parent
222fc87ade
commit
e1c8dbba97
2 changed files with 49 additions and 21 deletions
|
@ -25,6 +25,7 @@ func main() {
|
|||
Fatal(err)
|
||||
}
|
||||
defer devnull.Close()
|
||||
if len(os.Args) == 1 {
|
||||
if term.IsTerminal(0) {
|
||||
input := bufio.NewScanner(os.Stdin)
|
||||
for {
|
||||
|
@ -39,7 +40,9 @@ func main() {
|
|||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||
continue
|
||||
}
|
||||
executeScript(devnull, cmd)
|
||||
if err := executeScript(devnull, cmd); err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := input.Err(); err == io.EOF {
|
||||
break
|
||||
|
@ -52,7 +55,24 @@ func main() {
|
|||
if err != nil {
|
||||
Fatal("parse error: %v\n", err)
|
||||
}
|
||||
executeScript(devnull, script)
|
||||
if err := executeScript(devnull, script); err != nil {
|
||||
Fatal(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, scriptpath := range os.Args[1:] {
|
||||
f, err := os.Open(scriptpath)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
8
pkg/beam/examples/beamsh/helloworld.ds
Executable file
8
pkg/beam/examples/beamsh/helloworld.ds
Executable file
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env beamsh
|
||||
|
||||
print {
|
||||
trace {
|
||||
emit hello
|
||||
emit world
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue