Adds ability for the interpreter to read from stdin pipes via -run

This commit is contained in:
sloum 2022-06-02 09:21:34 -07:00
parent 1bf8fe8dce
commit 601995a6d9
4 changed files with 18 additions and 4 deletions

View File

@ -741,6 +741,12 @@ slope -run "(display (+ 1 3))"
You may, of course, replace the contents between the quotes with your own one liner. In general all features of slope are available from a one liner, including loading modules.
You may also leverage `-run` to create pipelines. By passing `--` to `-run` slope will read from `stdin` until `EOF`:
``` sh
cat myfile.slo myotherfile.slo | slope -run -- | less
```
You can, at your option, use the `-L` flag to preload the environment with your [preload](#preload) content.

View File

@ -446,7 +446,6 @@ func apply(procedure expression, args []expression) (value expression) {
en := &env{make(vars), p.en}
switch params := p.params.(type) {
case []expression:
fmt.Println(p)
if variadic(params) > len(args) {
return exception(fmt.Sprintf("Lambda expected %d arguments but received %d", len(params), len(args)))
}

13
main.go
View File

@ -16,7 +16,7 @@ import (
ln "github.com/peterh/liner"
)
const version = "0.7.0"
const version = "0.7.3"
const globalLibPath = "/usr/local/lib/slope/modules/"
@ -324,7 +324,16 @@ func main() {
if *preloadEnv {
preloadFiles()
}
RunCommand(*runCommand)
if *runCommand == "--" {
b, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not read from stdin")
SafeExit(1)
}
RunCommand(string(b))
} else {
RunCommand(*runCommand)
}
} else if len(args) > 0 {
if *preloadEnv {
preloadFiles()

View File

@ -25,7 +25,7 @@ Prints the version information and exits.
.TP
.B
\fB-run [program]\fP
Runs the given program, passed in as a quoted string, and exits, printing any output as directed by the given program.
Runs the given program, passed in as a quoted string, and exits, printing any output as directed by the given program. If \fI--\fP is given as an argument to \fB-run\fP slope will read from stdin until EOF.
.TP
.B
\fB-L\fP