mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 21:35:31 +02:00
Add support for multiline script files (#1386)
* Add support for multiline script files * clippy
This commit is contained in:
33
src/main.rs
33
src/main.rs
@ -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,
|
||||
))?;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user