nushell/crates/nu-protocol/src
Eric Hodel 7071617f18
Allow plugins to receive configuration from the nushell configuration (#10955)
# Description

When nushell calls a plugin it now sends a configuration `Value` from
the nushell config under `$env.config.plugins.PLUGIN_SHORT_NAME`. This
allows plugin authors to read configuration provided by plugin users.

The `PLUGIN_SHORT_NAME` must match the registered filename after
`nu_plugin_`. If you register `target/debug/nu_plugin_config` the
`PLUGIN_NAME` will be `config` and the nushell config will loook like:

        $env.config = {
          # ...
          plugins: {
            config: [
              some
              values
            ]
          }
        }

Configuration may also use a closure which allows passing values from
`$env` to a plugin:

        $env.config = {
          # ...
          plugins: {
            config: {||
              $env.some_value
            }
          }
        }

This is a breaking change for the plugin API as the `Plugin::run()`
function now accepts a new configuration argument which is an
`&Option<Value>`. If no configuration was supplied the value is `None`.

Plugins compiled after this change should work with older nushell, and
will behave as if the configuration was not set.

Initially discussed in #10867

# User-Facing Changes

* Plugins can read configuration data stored in `$env.config.plugins`
* The plugin `CallInfo` now includes a `config` entry, existing plugins
will require updates

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

- [ ] Update [Creating a plugin (in
Rust)](https://www.nushell.sh/contributor-book/plugins.html#creating-a-plugin-in-rust)
[source](https://github.com/nushell/nushell.github.io/blob/main/contributor-book/plugins.md)
- [ ] Add "Configuration" section to [Plugins
documentation](https://www.nushell.sh/contributor-book/plugins.html)
2024-01-15 16:59:47 +08:00
..
ast Fix incorrect handling of boolean flags for builtin commands (#11492) 2024-01-11 17:19:48 +02:00
config Allow plugins to receive configuration from the nushell configuration (#10955) 2024-01-15 16:59:47 +08:00
engine Allow plugins to receive configuration from the nushell configuration (#10955) 2024-01-15 16:59:47 +08:00
value Lock out new direct construction of Record (#11414) 2023-12-24 13:12:16 +01:00
alias.rs Refactor scope commands (#10023) 2023-08-17 11:58:38 +03:00
cli_error.rs Refactor and fix Config<->Value mechanism (#10896) 2023-11-08 20:31:30 +01:00
did_you_mean.rs Improve case insensitivity consistency (#10884) 2023-11-08 23:58:54 +01:00
eval_base.rs Allow spreading arguments to commands (#11289) 2023-12-28 15:43:20 +08:00
eval_const.rs Allow spreading arguments to commands (#11289) 2023-12-28 15:43:20 +08:00
example.rs remove unused imports: Deserialize, Serialize compiler warning for nu-protocol/src/example.rs (#8514) 2023-03-18 11:45:12 -07:00
exportable.rs Module: support defining const and use const variables inside of function (#9773) 2023-08-01 07:09:52 +08:00
id.rs Add virtual path abstraction layer (#9245) 2023-05-23 23:48:50 +03:00
lev_distance.rs Suggest existing variables on not found (#8902) 2023-05-02 18:17:14 +03:00
lib.rs Deprecate --flag: bool in custom command (#11365) 2023-12-21 10:07:08 +01:00
module.rs Error on use path item1 item2, if item1 is not a module (#11183) 2023-12-05 11:38:45 +01:00
parse_error.rs Allow spreading arguments to commands (#11289) 2023-12-28 15:43:20 +08:00
parse_warning.rs Deprecate --flag: bool in custom command (#11365) 2023-12-21 10:07:08 +01:00
pipeline_data.rs Don't create a thread if stderr_stream is None (#11421) 2023-12-25 08:10:15 -06:00
plugin_signature.rs Rename main to script name when running scripts (#9948) 2023-08-12 05:58:49 +12:00
shell_error.rs Allow spreading arguments to commands (#11289) 2023-12-28 15:43:20 +08:00
signature.rs Move history into their own module (#11308) 2023-12-15 13:17:12 +01:00
span.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
syntax_shape.rs Remove Expr::MatchPattern (#11367) 2023-12-20 18:52:28 +01:00
ty.rs adjust some commansd input_output type (#11436) 2024-01-15 16:58:26 +08:00
util.rs Convert more ShellError variants to named fields (#11173) 2023-11-28 06:43:51 -06:00
variable.rs Fix broken constants in scopes (#9679) 2023-07-14 00:02:05 +03:00