forked from extern/nushell
Prototype shebang support (#1368)
* Add shebang support to nu. * Move test file * Add test for scripts Co-authored-by: Jason Gedge <jason.gedge@shopify.com>
This commit is contained in:
parent
a29d52158e
commit
fb532f3f4e
39
src/main.rs
39
src/main.rs
@ -1,6 +1,8 @@
|
||||
use clap::{App, Arg};
|
||||
use log::LevelFilter;
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
use std::io::{prelude::*, BufReader};
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let matches = App::new("nushell")
|
||||
@ -38,6 +40,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.multiple(false)
|
||||
.takes_value(false),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("script")
|
||||
.help("the nu script to run")
|
||||
.index(1),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let loglevel = match matches.value_of("loglevel") {
|
||||
@ -76,6 +83,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
builder.try_init()?;
|
||||
|
||||
match matches.values_of("commands") {
|
||||
None => {}
|
||||
Some(values) => {
|
||||
@ -89,12 +98,30 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
}
|
||||
|
||||
builder.try_init()?;
|
||||
match matches.value_of("script") {
|
||||
Some(script) => {
|
||||
let file = File::open(script)?;
|
||||
let reader = BufReader::new(file);
|
||||
for line in reader.lines() {
|
||||
let line = line?;
|
||||
if !line.starts_with('#') {
|
||||
futures::executor::block_on(nu::run_pipeline_standalone(
|
||||
line,
|
||||
matches.is_present("stdin"),
|
||||
))?;
|
||||
}
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
None => {
|
||||
println!(
|
||||
"Welcome to Nushell {} (type 'help' for more info)",
|
||||
clap::crate_version!()
|
||||
);
|
||||
futures::executor::block_on(nu::cli())?;
|
||||
}
|
||||
}
|
||||
|
||||
println!(
|
||||
"Welcome to Nushell {} (type 'help' for more info)",
|
||||
clap::crate_version!()
|
||||
);
|
||||
futures::executor::block_on(nu::cli())?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -320,6 +320,10 @@ mod tests {
|
||||
loc: fixtures().join("sample_data.xlsx"),
|
||||
at: 0
|
||||
},
|
||||
Res {
|
||||
loc: fixtures().join("script.nu"),
|
||||
at: 0
|
||||
},
|
||||
Res {
|
||||
loc: fixtures().join("sgml_description.json"),
|
||||
at: 0
|
||||
|
2
tests/fixtures/formats/script.nu
vendored
Executable file
2
tests/fixtures/formats/script.nu
vendored
Executable file
@ -0,0 +1,2 @@
|
||||
#!/Users/gedge/src/github.com/nushell/nushell/target/debug/nu
|
||||
echo "done"
|
@ -122,6 +122,19 @@ mod nu_commands {
|
||||
}
|
||||
}
|
||||
|
||||
mod nu_script {
|
||||
use super::nu;
|
||||
|
||||
#[test]
|
||||
fn run_nu_script() {
|
||||
let actual = nu!(cwd: "tests/fixtures/formats", r#"
|
||||
nu script.nu
|
||||
"#);
|
||||
|
||||
assert_eq!(actual, "done");
|
||||
}
|
||||
}
|
||||
|
||||
mod tilde_expansion {
|
||||
use super::nu;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user