mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Support for custom values in plugin examples (#12213)
# 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
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use crate::{cool_custom_value::CoolCustomValue, CustomValuePlugin};
|
||||
|
||||
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, SimplePluginCommand};
|
||||
use nu_protocol::{Category, PluginSignature, Value};
|
||||
use nu_protocol::{Category, PluginExample, PluginSignature, Span, Value};
|
||||
|
||||
pub struct Generate;
|
||||
|
||||
@ -12,6 +12,11 @@ impl SimplePluginCommand for Generate {
|
||||
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(
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{second_custom_value::SecondCustomValue, CustomValuePlugin};
|
||||
|
||||
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, SimplePluginCommand};
|
||||
use nu_protocol::{Category, PluginSignature, SyntaxShape, Value};
|
||||
use nu_protocol::{Category, PluginExample, PluginSignature, Span, SyntaxShape, Value};
|
||||
|
||||
pub struct Generate2;
|
||||
|
||||
@ -17,6 +17,18 @@ impl SimplePluginCommand for Generate2 {
|
||||
"An optional closure to pass the custom value to",
|
||||
)
|
||||
.category(Category::Experimental)
|
||||
.plugin_examples(vec![
|
||||
PluginExample {
|
||||
example: "custom-value generate2".into(),
|
||||
description: "Generate a new SecondCustomValue".into(),
|
||||
result: Some(SecondCustomValue::new("xyz").into_value(Span::test_data())),
|
||||
},
|
||||
PluginExample {
|
||||
example: "custom-value generate2 { print }".into(),
|
||||
description: "Generate a new SecondCustomValue and pass it to a closure".into(),
|
||||
result: None,
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
fn run(
|
||||
|
@ -3,7 +3,7 @@ use crate::{
|
||||
};
|
||||
|
||||
use nu_plugin::{EngineInterface, EvaluatedCall, LabeledError, SimplePluginCommand};
|
||||
use nu_protocol::{Category, PluginSignature, ShellError, Value};
|
||||
use nu_protocol::{Category, PluginExample, PluginSignature, ShellError, Span, Value};
|
||||
|
||||
pub struct Update;
|
||||
|
||||
@ -14,6 +14,18 @@ impl SimplePluginCommand for Update {
|
||||
PluginSignature::build("custom-value update")
|
||||
.usage("PluginSignature for a plugin that updates a custom value")
|
||||
.category(Category::Experimental)
|
||||
.plugin_examples(vec![
|
||||
PluginExample {
|
||||
example: "custom-value generate | custom-value update".into(),
|
||||
description: "Update a CoolCustomValue".into(),
|
||||
result: Some(CoolCustomValue::new("abcxyz").into_value(Span::test_data())),
|
||||
},
|
||||
PluginExample {
|
||||
example: "custom-value generate | custom-value update".into(),
|
||||
description: "Update a SecondCustomValue".into(),
|
||||
result: Some(CoolCustomValue::new("xyzabc").into_value(Span::test_data())),
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
fn run(
|
||||
|
Reference in New Issue
Block a user