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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

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

View File

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

View File

@ -10,10 +10,15 @@ impl WholeStreamCommand for Command {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build("nu") Signature::build("nu")
.switch("stdin", "stdin", None) .switch("stdin", "redirect stdin", None)
.switch("skip-plugins", "do not load plugins", None) .switch("skip-plugins", "do not load plugins", None)
.switch("no-history", "don't save history", None) .switch("no-history", "don't save history", None)
.named("commands", SyntaxShape::String, "commands", Some('c')) .named(
"commands",
SyntaxShape::String,
"commands to run",
Some('c'),
)
.named( .named(
"testbin", "testbin",
SyntaxShape::String, SyntaxShape::String,
@ -34,8 +39,7 @@ impl WholeStreamCommand for Command {
"custom configuration source file", "custom configuration source file",
None, None,
) )
.optional("script", SyntaxShape::FilePath, "script to run") .rest(SyntaxShape::String, "source file(s) to run")
.rest(SyntaxShape::String, "...")
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {