mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 08:16:32 +02:00
Deprecate register
and add plugin use
(#12607)
# Description Adds a new keyword, `plugin use`. Unlike `register`, this merely loads the signatures from the plugin cache file. The file is configurable with the `--plugin-config` option either to `nu` or to `plugin use` itself, just like the other `plugin` family of commands. At the REPL, one might do this to replace `register`: ```nushell > plugin add ~/.cargo/bin/nu_plugin_foo > plugin use foo ``` This will not work in a script, because `plugin use` is a keyword and `plugin add` does not evaluate at parse time (intentionally). This means we no longer run random binaries during parse. The `--plugins` option has been added to allow running `nu` with certain plugins in one step. This is used especially for the `nu_with_plugins!` test macro, but I'd imagine is generally useful. The only weird quirk is that it has to be a list, and we don't really do this for any of our other CLI args at the moment. `register` now prints a deprecation parse warning. This should fix #11923, as we now have a complete alternative to `register`. # User-Facing Changes - Add `plugin use` command - Deprecate `register` - Add `--plugins` option to `nu` to replace a common use of `register` # Tests + Formatting I think I've tested it thoroughly enough and every existing test passes. Testing nu CLI options and alternate config files is a little hairy and I wish there were some more generic helpers for this, so this will go on my TODO list for refactoring. - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting - [ ] Update plugins sections of book - [ ] Release notes
This commit is contained in:
@ -1,26 +1,42 @@
|
||||
use nu_test_support::nu;
|
||||
|
||||
#[test]
|
||||
fn register() {
|
||||
let out = nu!("register crates/nu_plugin_nu_example/nu_plugin_nu_example.nu");
|
||||
assert!(out.status.success());
|
||||
assert!(out.out.trim().is_empty());
|
||||
assert!(out.err.trim().is_empty());
|
||||
}
|
||||
use assert_cmd::Command;
|
||||
|
||||
#[test]
|
||||
fn call() {
|
||||
let out = nu!(r#"
|
||||
register crates/nu_plugin_nu_example/nu_plugin_nu_example.nu
|
||||
nu_plugin_nu_example 4242 teststring
|
||||
"#);
|
||||
assert!(out.status.success());
|
||||
// Add the `nu` binaries to the path env
|
||||
let path_env = std::env::join_paths(
|
||||
std::iter::once(nu_test_support::fs::binaries()).chain(
|
||||
std::env::var_os(nu_test_support::NATIVE_PATH_ENV_VAR)
|
||||
.as_deref()
|
||||
.map(std::env::split_paths)
|
||||
.into_iter()
|
||||
.flatten(),
|
||||
),
|
||||
)
|
||||
.expect("failed to make path var");
|
||||
|
||||
assert!(out.err.contains("name: nu_plugin_nu_example"));
|
||||
assert!(out.err.contains("4242"));
|
||||
assert!(out.err.contains("teststring"));
|
||||
let assert = Command::new(nu_test_support::fs::executable_path())
|
||||
.env(nu_test_support::NATIVE_PATH_ENV_VAR, path_env)
|
||||
.args([
|
||||
"--no-config-file",
|
||||
"--no-std-lib",
|
||||
"--plugins",
|
||||
&format!(
|
||||
"[crates{0}nu_plugin_nu_example{0}nu_plugin_nu_example.nu]",
|
||||
std::path::MAIN_SEPARATOR
|
||||
),
|
||||
"--commands",
|
||||
"nu_plugin_nu_example 4242 teststring",
|
||||
])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
assert!(out.out.contains("one"));
|
||||
assert!(out.out.contains("two"));
|
||||
assert!(out.out.contains("three"));
|
||||
let output = assert.get_output();
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(stdout.contains("one"));
|
||||
assert!(stdout.contains("two"));
|
||||
assert!(stdout.contains("three"));
|
||||
assert!(stderr.contains("name: nu_plugin_nu_example"));
|
||||
assert!(stderr.contains("4242"));
|
||||
assert!(stderr.contains("teststring"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user