nushell/tests/plugins
Devyn Cairns f3843a6176
Make plugins able to find and call other commands (#13407)
# Description

Adds functionality to the plugin interface to support calling internal
commands from plugins. For example, using `view ir --json`:

```rust
let closure: Value = call.req(0)?;

let Some(decl_id) = engine.find_decl("view ir")? else {
    return Err(LabeledError::new("`view ir` not found"));
};

let ir_json = engine.call_decl(
    decl_id,
    EvaluatedCall::new(call.head)
        .with_named("json".into_spanned(call.head), Value::bool(true, call.head))
        .with_positional(closure),
    PipelineData::Empty,
    true,
    false,
)?.into_value()?.into_string()?;

let ir = serde_json::from_value(&ir_json);

// ...
```

# User-Facing Changes

Plugin developers can now use `EngineInterface::find_decl()` and
`call_decl()` to call internal commands, which could be handy for
formatters like `to csv` or `to nuon`, or for reflection commands that
help gain insight into the engine.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting
- [ ] release notes
- [ ] update plugin protocol documentation: `FindDecl`, `CallDecl`
engine calls; `Identifier` engine call response
2024-07-19 13:54:21 +08:00
..
formats Avoid taking unnecessary ownership of intermediates (#12740) 2024-05-04 00:53:15 +00:00
call_decl.rs Make plugins able to find and call other commands (#13407) 2024-07-19 13:54:21 +08:00
config.rs Use IntoValue and FromValue derive macros in nu_plugin_example for example usage (#13220) 2024-06-26 17:50:14 -05:00
core_inc.rs Avoid taking unnecessary ownership of intermediates (#12740) 2024-05-04 00:53:15 +00:00
custom_values.rs Fix deadlock on PluginCustomValue drop (#12418) 2024-04-05 21:57:00 -05:00
env.rs Merge stream_example into example plugin and clean up names (#12234) 2024-03-19 12:36:46 -05:00
mod.rs Make plugins able to find and call other commands (#13407) 2024-07-19 13:54:21 +08:00
nu_plugin_nu_example.rs Path migration part 2: nu-test-support (#13329) 2024-07-12 02:43:10 +00:00
register.rs Change PluginCommand API to be more like Command (#12279) 2024-03-27 11:59:57 +01:00
registry_file.rs Path migration part 2: nu-test-support (#13329) 2024-07-12 02:43:10 +00:00
stream.rs Replace ExternalStream with new ByteStream type (#12774) 2024-05-16 07:11:18 -07:00
stress_internals.rs Fix (and test) for a deadlock that can happen while waiting for protocol info (#12633) 2024-04-24 08:44:04 -05:00