mirror of
https://github.com/nushell/nushell.git
synced 2025-02-23 05:51:28 +01:00
Make sure that scripts can also have custom commands. (#3309)
With the current code it is possible to attach custom commands from a custom binary, but only for interactive mode. This change makes it possible to also customize the evaluation context for commands and scripts.
This commit is contained in:
parent
a92ff57270
commit
e8bc319f08
@ -1,6 +1,5 @@
|
|||||||
use crate::line_editor::configure_ctrl_c;
|
use crate::line_editor::configure_ctrl_c;
|
||||||
use nu_ansi_term::Color;
|
use nu_ansi_term::Color;
|
||||||
use nu_command::commands::default_context::create_default_context;
|
|
||||||
use nu_engine::{maybe_print_errors, run_block, script::run_script_standalone, EvaluationContext};
|
use nu_engine::{maybe_print_errors, run_block, script::run_script_standalone, EvaluationContext};
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
@ -124,9 +123,7 @@ pub fn search_paths() -> Vec<std::path::PathBuf> {
|
|||||||
search_paths
|
search_paths
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_script_file(options: Options) -> Result<(), Box<dyn Error>> {
|
pub fn run_script_file(context: EvaluationContext, options: Options) -> Result<(), Box<dyn Error>> {
|
||||||
let context = create_default_context(false)?;
|
|
||||||
|
|
||||||
if let Some(cfg) = options.config {
|
if let Some(cfg) = options.config {
|
||||||
load_cfg_as_global_cfg(&context, PathBuf::from(cfg));
|
load_cfg_as_global_cfg(&context, PathBuf::from(cfg));
|
||||||
} else {
|
} else {
|
||||||
|
@ -150,7 +150,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
Some(values) => {
|
Some(values) => {
|
||||||
options.scripts = vec![NuScript::code(values)?];
|
options.scripts = vec![NuScript::code(values)?];
|
||||||
|
|
||||||
nu_cli::run_script_file(options)?;
|
let context = create_default_context(false)?;
|
||||||
|
nu_cli::run_script_file(context, options)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,7 +162,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
options.scripts = vec![NuScript::source_file(filepath.as_os_str())?];
|
options.scripts = vec![NuScript::source_file(filepath.as_os_str())?];
|
||||||
|
|
||||||
nu_cli::run_script_file(options)?;
|
let context = create_default_context(false)?;
|
||||||
|
nu_cli::run_script_file(context, options)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user