mirror of
https://github.com/nushell/nushell.git
synced 2025-08-12 16:57:11 +02:00
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:
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(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user