Revert "Getting closer to multiline scripts (#2738)" (#2745)

This reverts commit e66bf70589.
This commit is contained in:
Jonathan Turner
2020-11-10 18:22:13 +13:00
committed by GitHub
parent e66bf70589
commit 5a75e11b0e
17 changed files with 160 additions and 262 deletions

View File

@ -4,7 +4,7 @@ use nu_cli::create_default_context;
use nu_cli::utils::test_bins as binaries;
use std::error::Error;
use std::fs::File;
use std::io::prelude::*;
use std::io::{prelude::*, BufReader};
fn main() -> Result<(), Box<dyn Error>> {
let matches = App::new("nushell")
@ -124,12 +124,9 @@ fn main() -> Result<(), Box<dyn Error>> {
match matches.values_of("commands") {
None => {}
Some(values) => {
let script_text: String = values
.map(|x| x.to_string())
.collect::<Vec<String>>()
.join("\n");
futures::executor::block_on(nu_cli::run_script_file(
script_text,
let pipelines: Vec<String> = values.map(|x| x.to_string()).collect();
futures::executor::block_on(nu_cli::run_vec_of_pipelines(
pipelines,
matches.is_present("stdin"),
))?;
return Ok(());
@ -138,12 +135,25 @@ fn main() -> Result<(), Box<dyn Error>> {
match matches.value_of("script") {
Some(script) => {
let mut file = File::open(script)?;
let mut buffer = String::new();
file.read_to_string(&mut buffer)?;
let file = File::open(script)?;
let reader = BufReader::new(file);
let pipelines: Vec<String> = reader
.lines()
.filter_map(|x| {
if let Ok(x) = x {
if !x.starts_with('#') {
Some(x)
} else {
None
}
} else {
None
}
})
.collect();
futures::executor::block_on(nu_cli::run_script_file(
buffer,
futures::executor::block_on(nu_cli::run_vec_of_pipelines(
pipelines,
matches.is_present("stdin"),
))?;
return Ok(());