From 0eae9c49b01e361e867fce4b26bf1b9abca7e841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Tue, 15 Jun 2021 20:38:56 -0500 Subject: [PATCH] Nu's rest arguments are source(s) files scripts to run. (#3624) --- crates/nu-cli/src/app.rs | 15 +++++++++++---- crates/nu-cli/src/app/options.rs | 4 ++-- crates/nu-command/src/commands/nu/command.rs | 12 ++++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/crates/nu-cli/src/app.rs b/crates/nu-cli/src/app.rs index 7c3ced79b..68cf85f0a 100644 --- a/crates/nu-cli/src/app.rs +++ b/crates/nu-cli/src/app.rs @@ -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::>(); - 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)?; diff --git a/crates/nu-cli/src/app/options.rs b/crates/nu-cli/src/app/options.rs index c14d87b7d..96e79a59f 100644 --- a/crates/nu-cli/src/app/options.rs +++ b/crates/nu-cli/src/app/options.rs @@ -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, pub stdin: bool, @@ -64,7 +64,7 @@ impl Options { } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct NuScript { pub filepath: Option, pub contents: String, diff --git a/crates/nu-command/src/commands/nu/command.rs b/crates/nu-command/src/commands/nu/command.rs index e8b5700a2..eb0d0a6a2 100644 --- a/crates/nu-command/src/commands/nu/command.rs +++ b/crates/nu-command/src/commands/nu/command.rs @@ -10,10 +10,15 @@ impl WholeStreamCommand for Command { fn signature(&self) -> Signature { Signature::build("nu") - .switch("stdin", "stdin", None) + .switch("stdin", "redirect stdin", None) .switch("skip-plugins", "do not load plugins", 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( "testbin", SyntaxShape::String, @@ -34,8 +39,7 @@ impl WholeStreamCommand for Command { "custom configuration source file", None, ) - .optional("script", SyntaxShape::FilePath, "script to run") - .rest(SyntaxShape::String, "...") + .rest(SyntaxShape::String, "source file(s) to run") } fn usage(&self) -> &str {