mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 03:38:33 +02:00
Add alias support to scripts and -c (#1593)
This commit is contained in:
70
src/main.rs
70
src/main.rs
@ -3,7 +3,6 @@ use log::LevelFilter;
|
||||
use std::error::Error;
|
||||
use std::fs::File;
|
||||
use std::io::{prelude::*, BufReader};
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let matches = App::new("nushell")
|
||||
@ -89,28 +88,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
match matches.values_of("commands") {
|
||||
None => {}
|
||||
Some(values) => {
|
||||
let mut syncer = nu_cli::EnvironmentSyncer::new();
|
||||
let mut context = nu_cli::create_default_context(&mut syncer)?;
|
||||
|
||||
let _ = nu_cli::load_plugins(&mut context);
|
||||
|
||||
let cc = context.ctrl_c.clone();
|
||||
|
||||
ctrlc::set_handler(move || {
|
||||
cc.store(true, Ordering::SeqCst);
|
||||
})
|
||||
.expect("Error setting Ctrl-C handler");
|
||||
|
||||
if context.ctrl_c.load(Ordering::SeqCst) {
|
||||
context.ctrl_c.store(false, Ordering::SeqCst);
|
||||
}
|
||||
for item in values {
|
||||
futures::executor::block_on(nu_cli::run_pipeline_standalone(
|
||||
item.into(),
|
||||
matches.is_present("stdin"),
|
||||
&mut context,
|
||||
))?;
|
||||
}
|
||||
let pipelines: Vec<String> = values.map(|x| x.to_string()).collect();
|
||||
futures::executor::block_on(nu_cli::run_vec_of_pipelines(
|
||||
pipelines,
|
||||
matches.is_present("stdin"),
|
||||
))?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@ -119,31 +101,25 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
Some(script) => {
|
||||
let file = File::open(script)?;
|
||||
let reader = BufReader::new(file);
|
||||
let mut syncer = nu_cli::EnvironmentSyncer::new();
|
||||
let mut context = nu_cli::create_default_context(&mut syncer)?;
|
||||
let pipelines: Vec<String> = reader
|
||||
.lines()
|
||||
.filter_map(|x| {
|
||||
if let Ok(x) = x {
|
||||
if !x.starts_with('#') {
|
||||
Some(x)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
let _ = nu_cli::load_plugins(&mut context);
|
||||
|
||||
let cc = context.ctrl_c.clone();
|
||||
|
||||
ctrlc::set_handler(move || {
|
||||
cc.store(true, Ordering::SeqCst);
|
||||
})
|
||||
.expect("Error setting Ctrl-C handler");
|
||||
|
||||
if context.ctrl_c.load(Ordering::SeqCst) {
|
||||
context.ctrl_c.store(false, Ordering::SeqCst);
|
||||
}
|
||||
for line in reader.lines() {
|
||||
let line = line?;
|
||||
if !line.starts_with('#') {
|
||||
futures::executor::block_on(nu_cli::run_pipeline_standalone(
|
||||
line,
|
||||
matches.is_present("stdin"),
|
||||
&mut context,
|
||||
))?;
|
||||
}
|
||||
}
|
||||
futures::executor::block_on(nu_cli::run_vec_of_pipelines(
|
||||
pipelines,
|
||||
matches.is_present("stdin"),
|
||||
))?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user