feat: initial commit.
This commit is contained in:
+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