# Description @ayax79 says that the dataframe commands all have dataframe custom values in their examples, and they're used for tests. Rather than send the custom values to the engine, if they're in examples, this change just renders them using `to_base_value()` first. That way we avoid potentially having to hold onto custom values in `plugins.nu` that might not be valid indefinitely - as will be the case for dataframes in particular - but we still avoid forcing plugin writers to not use custom values in their examples. # User-Facing Changes - Custom values usable in plugin examples # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting
32 lines
1.1 KiB
Rust
32 lines
1.1 KiB
Rust
use crate::{cool_custom_value::CoolCustomValue, CustomValuePlugin};
|
|
|
|
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, SimplePluginCommand};
|
|
use nu_protocol::{Category, PluginExample, PluginSignature, Span, Value};
|
|
|
|
pub struct Generate;
|
|
|
|
impl SimplePluginCommand for Generate {
|
|
type Plugin = CustomValuePlugin;
|
|
|
|
fn signature(&self) -> PluginSignature {
|
|
PluginSignature::build("custom-value generate")
|
|
.usage("PluginSignature for a plugin that generates a custom value")
|
|
.category(Category::Experimental)
|
|
.plugin_examples(vec![PluginExample {
|
|
example: "custom-value generate".into(),
|
|
description: "Generate a new CoolCustomValue".into(),
|
|
result: Some(CoolCustomValue::new("abc").into_value(Span::test_data())),
|
|
}])
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
_plugin: &CustomValuePlugin,
|
|
_engine: &EngineInterface,
|
|
call: &EvaluatedCall,
|
|
_input: &Value,
|
|
) -> Result<Value, LabeledError> {
|
|
Ok(CoolCustomValue::new("abc").into_value(call.head))
|
|
}
|
|
}
|