Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ Or if you'd like to use Boa's REPL, simply type:
boa
```

You can also pipe JavaScript into Boa:

```shell
echo 'console.log(1 + 2)' | boa
cat script.js | boa
boa < script.js
Comment thread
Nakshatra480 marked this conversation as resolved.
```

## CLI Options

```txt
Expand Down
12 changes: 11 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use std::{
cell::RefCell,
collections::VecDeque,
fs::OpenOptions,
io,
io::{self, IsTerminal, Read},
path::{Path, PathBuf},
rc::Rc,
thread,
Expand Down Expand Up @@ -571,6 +571,16 @@ fn main() -> Result<()> {
} else if let Some(ref expr) = args.expression {
evaluate_expr(expr, &args, &mut context, &printer)?;
return Ok(());
} else if !io::stdin().is_terminal() {
let mut input = String::new();
io::stdin()
.read_to_string(&mut input)
.wrap_err("failed to read stdin")?;
return if input.is_empty() {
Ok(())
} else {
evaluate_expr(&input, &args, &mut context, &printer)
};
}

let handle = start_readline_thread(sender, printer.clone(), args.vi_mode);
Expand Down
Loading