mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
Core nu plugin load capability. (#2544)
We introduce the `plugin` nu sub command (`nu plugin`) with basic plugin loading support. We can choose to load plugins from a directory. Originally introduced to make integration tests faster (by not loading any plugins on startup at all) but `nu plugin --load some_path ; test_pipeline_that_uses_plugins_just_loaded` does not see it. Therefore, a `nu_with_plugins!` macro for tests was introduced on top of nu`s `--skip-plugins` switch executable which is set to true when running the integration tests that use the `nu!` macro now..
This commit is contained in:
committed by
GitHub
parent
e05e6b42fe
commit
0178b53289
@ -14,6 +14,83 @@ macro_rules! nu {
|
||||
nu!($cwd, $path)
|
||||
}};
|
||||
|
||||
($cwd:expr, $path:expr) => {{
|
||||
pub use std::error::Error;
|
||||
pub use std::io::prelude::*;
|
||||
pub use std::process::{Command, Stdio};
|
||||
|
||||
let commands = &*format!(
|
||||
"
|
||||
cd \"{}\"
|
||||
{}
|
||||
exit",
|
||||
$crate::fs::in_directory($cwd),
|
||||
$crate::fs::DisplayPath::display_path(&$path)
|
||||
);
|
||||
|
||||
let test_bins = $crate::fs::binaries();
|
||||
let test_bins = dunce::canonicalize(&test_bins).unwrap_or_else(|e| {
|
||||
panic!(
|
||||
"Couldn't canonicalize dummy binaries path {}: {:?}",
|
||||
test_bins.display(),
|
||||
e
|
||||
)
|
||||
});
|
||||
|
||||
let mut paths = $crate::shell_os_paths();
|
||||
paths.insert(0, test_bins);
|
||||
|
||||
let paths_joined = match std::env::join_paths(paths.iter()) {
|
||||
Ok(all) => all,
|
||||
Err(_) => panic!("Couldn't join paths for PATH var."),
|
||||
};
|
||||
|
||||
let mut process = match Command::new($crate::fs::executable_path())
|
||||
.env("PATH", paths_joined)
|
||||
.arg("--skip-plugins")
|
||||
.stdout(Stdio::piped())
|
||||
.stdin(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
{
|
||||
Ok(child) => child,
|
||||
Err(why) => panic!("Can't run test {}", why.to_string()),
|
||||
};
|
||||
|
||||
let stdin = process.stdin.as_mut().expect("couldn't open stdin");
|
||||
stdin
|
||||
.write_all(commands.as_bytes())
|
||||
.expect("couldn't write to stdin");
|
||||
|
||||
let output = process
|
||||
.wait_with_output()
|
||||
.expect("couldn't read from stdout/stderr");
|
||||
|
||||
let out = $crate::macros::read_std(&output.stdout);
|
||||
let err = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
println!("=== stderr\n{}", err);
|
||||
|
||||
$crate::macros::Outcome::new(out,err.into_owned())
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! nu_with_plugins {
|
||||
(cwd: $cwd:expr, $path:expr, $($part:expr),*) => {{
|
||||
use $crate::fs::DisplayPath;
|
||||
|
||||
let path = format!($path, $(
|
||||
$part.display_path()
|
||||
),*);
|
||||
|
||||
nu_with_plugins!($cwd, &path)
|
||||
}};
|
||||
|
||||
(cwd: $cwd:expr, $path:expr) => {{
|
||||
nu_with_plugins!($cwd, $path)
|
||||
}};
|
||||
|
||||
($cwd:expr, $path:expr) => {{
|
||||
pub use std::error::Error;
|
||||
pub use std::io::prelude::*;
|
||||
|
Reference in New Issue
Block a user