feat: initial commit.
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
/target
|
||||||
Generated
+2378
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "nu_plugin_mynu"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nu-plugin = "0.115.1"
|
||||||
|
nu-protocol = "0.115.1"
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
use nu_plugin::{MsgPackSerializer, Plugin, PluginCommand, SimplePluginCommand, serve_plugin};
|
||||||
|
use nu_protocol::{LabeledError, Signature, Type, Value};
|
||||||
|
|
||||||
|
struct MyPlugin;
|
||||||
|
|
||||||
|
impl Plugin for MyPlugin {
|
||||||
|
fn version(&self) -> String {
|
||||||
|
env!("CARGO_PKG_VERSION").into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn commands(&self) -> Vec<Box<dyn nu_plugin::PluginCommand<Plugin = Self>>> {
|
||||||
|
vec![Box::new(MyCommand)]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MyCommand;
|
||||||
|
|
||||||
|
impl SimplePluginCommand for MyCommand {
|
||||||
|
type Plugin = MyPlugin;
|
||||||
|
|
||||||
|
fn name(&self) -> &str {
|
||||||
|
"mynu"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn signature(&self) -> nu_protocol::Signature {
|
||||||
|
Signature::build(PluginCommand::name(self)).input_output_type(Type::String, Type::String)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn description(&self) -> &str {
|
||||||
|
"A learning rust plugin"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(
|
||||||
|
&self,
|
||||||
|
_plugin: &Self::Plugin,
|
||||||
|
_engine: &nu_plugin::EngineInterface,
|
||||||
|
_call: &nu_plugin::EvaluatedCall,
|
||||||
|
input: &nu_protocol::Value,
|
||||||
|
) -> Result<nu_protocol::Value, nu_protocol::LabeledError> {
|
||||||
|
match input {
|
||||||
|
Value::String { val, .. } => {
|
||||||
|
Ok(Value::string(format!("Hello, {}!", val), input.span()))
|
||||||
|
}
|
||||||
|
_ => Err(LabeledError::new("Expected String input").into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
serve_plugin(&MyPlugin {}, MsgPackSerializer)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user