forked from extern/nushell
Nu's rest arguments are source(s) files scripts to run. (#3624)
This commit is contained in:
parent
d0bca1fb0f
commit
0eae9c49b0
@ -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)?;
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user