mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 10:25:42 +02:00
account for startup commands in the scope. (#3261)
* Revert "Impl one configurable function to run scripts (#3242)" * pass config startup.
This commit is contained in:
committed by
GitHub
parent
4c09716ad8
commit
00acf22f5f
34
src/main.rs
34
src/main.rs
@ -1,10 +1,8 @@
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use clap::{App, Arg};
|
||||
use log::LevelFilter;
|
||||
use nu_cli::{create_default_context, Options};
|
||||
use nu_cli::{create_default_context, NuScript, Options};
|
||||
use nu_command::utils::test_bins as binaries;
|
||||
use nu_engine::filesystem::filesystem_shell::FilesystemShellMode;
|
||||
use nu_protocol::{NuScript, RunScriptOptions};
|
||||
use std::{error::Error, path::PathBuf};
|
||||
use std::error::Error;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let mut options = Options::new();
|
||||
@ -150,29 +148,25 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
match matches.values_of("commands") {
|
||||
None => {}
|
||||
Some(values) => {
|
||||
options.scripts = values
|
||||
.map(|cmd| NuScript::Content(cmd.to_string()))
|
||||
.collect();
|
||||
let mut run_options = script_options_from_matches(&matches);
|
||||
// we always exit on err
|
||||
run_options.exit_on_error = true;
|
||||
futures::executor::block_on(nu_cli::run_script_file(options, run_options))?;
|
||||
options.scripts = vec![NuScript::code(values)?];
|
||||
|
||||
futures::executor::block_on(nu_cli::run_script_file(options))?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
match matches.value_of("script") {
|
||||
Some(filepath) => {
|
||||
options.scripts = vec![NuScript::File(PathBuf::from(filepath))];
|
||||
let mut run_options = script_options_from_matches(&matches);
|
||||
// we always exit on err
|
||||
run_options.exit_on_error = true;
|
||||
futures::executor::block_on(nu_cli::run_script_file(options, run_options))?;
|
||||
let filepath = std::ffi::OsString::from(filepath);
|
||||
|
||||
options.scripts = vec![NuScript::source_file(filepath.as_os_str())?];
|
||||
|
||||
futures::executor::block_on(nu_cli::run_script_file(options))?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
None => {
|
||||
let context = create_default_context(FilesystemShellMode::Cli, true)?;
|
||||
let context = create_default_context(true)?;
|
||||
|
||||
if !matches.is_present("skip-plugins") {
|
||||
let _ = nu_cli::register_plugins(&context);
|
||||
@ -192,7 +186,3 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn script_options_from_matches(matches: &ArgMatches) -> RunScriptOptions {
|
||||
RunScriptOptions::default().with_stdin(matches.is_present("stdin"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user