Add support for multiline script files (#1386)

* Add support for multiline script files

* clippy
This commit is contained in:
Jonathan Turner
2020-02-13 21:24:18 -08:00
committed by GitHub
parent 473e9f9422
commit 8ae8ebd107
9 changed files with 64 additions and 22 deletions

View File

@ -3,6 +3,7 @@ use log::LevelFilter;
use std::error::Error;
use std::fs::File;
use std::io::{prelude::*, BufReader};
use std::sync::atomic::Ordering;
fn main() -> Result<(), Box<dyn Error>> {
let matches = App::new("nushell")
@ -88,10 +89,26 @@ fn main() -> Result<(), Box<dyn Error>> {
match matches.values_of("commands") {
None => {}
Some(values) => {
let mut syncer = nu::EnvironmentSyncer::new();
let mut context = nu::create_default_context(&mut syncer)?;
let _ = nu::load_plugins(&mut context);
let cc = context.ctrl_c.clone();
ctrlc::set_handler(move || {
cc.store(true, Ordering::SeqCst);
})
.expect("Error setting Ctrl-C handler");
if context.ctrl_c.load(Ordering::SeqCst) {
context.ctrl_c.store(false, Ordering::SeqCst);
}
for item in values {
futures::executor::block_on(nu::run_pipeline_standalone(
item.into(),
matches.is_present("stdin"),
&mut context,
))?;
}
return Ok(());
@ -102,12 +119,28 @@ fn main() -> Result<(), Box<dyn Error>> {
Some(script) => {
let file = File::open(script)?;
let reader = BufReader::new(file);
let mut syncer = nu::EnvironmentSyncer::new();
let mut context = nu::create_default_context(&mut syncer)?;
let _ = nu::load_plugins(&mut context);
let cc = context.ctrl_c.clone();
ctrlc::set_handler(move || {
cc.store(true, Ordering::SeqCst);
})
.expect("Error setting Ctrl-C handler");
if context.ctrl_c.load(Ordering::SeqCst) {
context.ctrl_c.store(false, Ordering::SeqCst);
}
for line in reader.lines() {
let line = line?;
if !line.starts_with('#') {
futures::executor::block_on(nu::run_pipeline_standalone(
line,
matches.is_present("stdin"),
&mut context,
))?;
}
}