Nu's rest arguments are source(s) files scripts to run. (#3624)

This commit is contained in:
Andrés N. Robalino
2021-06-15 20:38:56 -05:00
committed by GitHub
parent d0bca1fb0f
commit 0eae9c49b0
3 changed files with 21 additions and 10 deletions

View File

@ -110,7 +110,7 @@ impl App {
}
if let Some(scripts) = self.scripts() {
opts.scripts = scripts
let source_files = scripts
.into_iter()
.filter_map(Result::ok)
.map(|path| {
@ -119,10 +119,17 @@ impl App {
NuScript::source_file(path.as_os_str())
})
.filter_map(Result::ok)
.collect();
.collect::<Vec<_>>();
let context = crate::create_default_context(false)?;
return crate::run_script_file(context, opts);
for file in source_files {
let mut opts = opts.clone();
opts.scripts = vec![file];
let context = crate::create_default_context(false)?;
crate::run_script_file(context, opts)?;
}
return Ok(());
}
let context = crate::create_default_context(true)?;

View File

@ -4,7 +4,7 @@ use nu_protocol::{UntaggedValue, Value};
use std::cell::RefCell;
use std::ffi::{OsStr, OsString};
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct CliOptions {
pub config: Option<OsString>,
pub stdin: bool,
@ -64,7 +64,7 @@ impl Options {
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct NuScript {
pub filepath: Option<OsString>,
pub contents: String,