mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +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:
@ -5149,12 +5149,24 @@ pub fn parse_expression(working_set: &mut StateWorkingSet, spans: &[Span]) -> Ex
|
||||
#[cfg(feature = "plugin")]
|
||||
b"register" => {
|
||||
working_set.error(ParseError::BuiltinCommandInPipeline(
|
||||
"plugin".into(),
|
||||
"register".into(),
|
||||
spans[0],
|
||||
));
|
||||
|
||||
parse_call(working_set, &spans[pos..], spans[0])
|
||||
}
|
||||
#[cfg(feature = "plugin")]
|
||||
b"plugin" => {
|
||||
if spans.len() > 1 && working_set.get_span_contents(spans[1]) == b"use" {
|
||||
// only 'plugin use' is banned
|
||||
working_set.error(ParseError::BuiltinCommandInPipeline(
|
||||
"plugin use".into(),
|
||||
spans[0],
|
||||
));
|
||||
}
|
||||
|
||||
parse_call(working_set, &spans[pos..], spans[0])
|
||||
}
|
||||
|
||||
_ => parse_call(working_set, &spans[pos..], spans[0]),
|
||||
}
|
||||
@ -5286,6 +5298,20 @@ pub fn parse_builtin_commands(
|
||||
b"where" => parse_where(working_set, lite_command),
|
||||
#[cfg(feature = "plugin")]
|
||||
b"register" => parse_register(working_set, lite_command),
|
||||
// Only "plugin use" is a keyword
|
||||
#[cfg(feature = "plugin")]
|
||||
b"plugin"
|
||||
if lite_command
|
||||
.parts
|
||||
.get(1)
|
||||
.is_some_and(|span| working_set.get_span_contents(*span) == b"use") =>
|
||||
{
|
||||
if let Some(redirection) = lite_command.redirection.as_ref() {
|
||||
working_set.error(redirecting_builtin_error("plugin use", redirection));
|
||||
return garbage_pipeline(&lite_command.parts);
|
||||
}
|
||||
parse_keyword(working_set, lite_command)
|
||||
}
|
||||
_ => {
|
||||
let element = parse_pipeline_element(working_set, lite_command);
|
||||
|
||||
|
Reference in New Issue
Block a user