Plugins without file (#4650)

* adding plugin location in script

* adding plugin location in script
This commit is contained in:
Fernando Herrera 2022-02-26 08:57:51 +00:00 committed by GitHub
parent ed46f0ea17
commit 3eca43c0bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View file

@ -19,12 +19,10 @@ const PLUGIN_FILE: &str = "plugin.nu";
pub(crate) fn read_plugin_file(engine_state: &mut EngineState, stack: &mut Stack) {
// Reading signatures from signature file
// The plugin.nu file stores the parsed signature collected from each registered plugin
if let Some(mut plugin_path) = nu_path::config_dir() {
// Path to store plugins signatures
plugin_path.push(NUSHELL_FOLDER);
plugin_path.push(PLUGIN_FILE);
engine_state.plugin_signatures = Some(plugin_path.clone());
add_plugin_file(engine_state);
let plugin_path = engine_state.plugin_signatures.clone();
if let Some(plugin_path) = plugin_path {
let plugin_filename = plugin_path.to_string_lossy().to_owned();
if let Ok(contents) = std::fs::read(&plugin_path) {
@ -37,11 +35,22 @@ pub(crate) fn read_plugin_file(engine_state: &mut EngineState, stack: &mut Stack
);
}
}
if is_perf_true() {
info!("read_plugin_file {}:{}:{}", file!(), line!(), column!());
}
}
#[cfg(feature = "plugin")]
pub(crate) fn add_plugin_file(engine_state: &mut EngineState) {
if let Some(mut plugin_path) = nu_path::config_dir() {
// Path to store plugins signatures
plugin_path.push(NUSHELL_FOLDER);
plugin_path.push(PLUGIN_FILE);
engine_state.plugin_signatures = Some(plugin_path.clone());
}
}
pub(crate) fn read_config_file(
engine_state: &mut EngineState,
stack: &mut Stack,

View file

@ -191,6 +191,9 @@ fn main() -> Result<()> {
}
if let Some(commands) = &binary_args.commands {
#[cfg(feature = "plugin")]
config_files::add_plugin_file(&mut engine_state);
let ret_val = commands::evaluate(commands, &init_cwd, &mut engine_state, input);
if is_perf_true() {
info!("-c command execution {}:{}:{}", file!(), line!(), column!());
@ -198,6 +201,9 @@ fn main() -> Result<()> {
ret_val
} else if !script_name.is_empty() && binary_args.interactive_shell.is_none() {
#[cfg(feature = "plugin")]
config_files::add_plugin_file(&mut engine_state);
let ret_val =
eval_file::evaluate(script_name, &args_to_script, &mut engine_state, input);
if is_perf_true() {