Created
December 5, 2025 20:39
-
-
Save punund/6c78f75752a0f3f7a99a6986540a8dc7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use nu_plugin::{serve_plugin, EvaluatedCall, JsonSerializer}; | |
| use nu_plugin::{ | |
| EngineInterface, Plugin, PluginCommand, SimplePluginCommand, | |
| }; | |
| use nu_protocol::{LabeledError, PipelineData, Signature, Type}; | |
| struct SocketPlugin; | |
| impl Plugin for SocketPlugin { | |
| fn version(&self) -> String { | |
| env!("CARGO_PKG_VERSION").into() | |
| } | |
| fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> { | |
| vec![ | |
| Box::new(Socket), | |
| // Box::new(Connect), | |
| // When you add `Listen`, you'll just add `Box::new(Listen)` here. | |
| ] | |
| } | |
| } | |
| struct Socket; | |
| impl PluginCommand for Socket { | |
| type Plugin = SocketPlugin; | |
| fn name(&self) -> &str { | |
| "socket" | |
| } | |
| fn description(&self) -> &str { | |
| "create clients and servers using network sockets" | |
| } | |
| fn signature(&self) -> Signature { | |
| Signature::build(PluginCommand::name(self)) | |
| .input_output_type(Type::String, Type::Int) | |
| } | |
| fn run( | |
| &self, | |
| _plugin: &Self::Plugin, | |
| _engine: &EngineInterface, | |
| _call: &EvaluatedCall, | |
| _input: PipelineData, | |
| ) -> Result<PipelineData, LabeledError> { | |
| Ok(PipelineData::empty()) | |
| } | |
| } | |
| fn main() { | |
| serve_plugin(&SocketPlugin, JsonSerializer) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment