Skip to content

Instantly share code, notes, and snippets.

@daschl
Created October 19, 2020 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daschl/f655121f46c6182fdd13c13022d96765 to your computer and use it in GitHub Desktop.
Save daschl/f655121f46c6182fdd13c13022d96765 to your computer and use it in GitHub Desktop.
//! Helps to wrap plugins into commands for direct inclusion
use nu_plugin::Plugin;
use nu_cli::{CommandArgs, CommandRegistry, OutputStream, WholeStreamCommand};
use async_trait::async_trait;
use nu_protocol::Signature;
use nu_errors::ShellError;
pub struct PluginCommand<P> {
signature: Signature,
plugin: P,
}
impl<P: Plugin + Send + Sync> PluginCommand<P> {
pub fn new(mut plugin: P) -> Self {
let signature = plugin.config().as_ref().unwrap().clone();
Self { plugin, signature }
}
}
#[async_trait]
impl<P: Plugin + Send + Sync> WholeStreamCommand for PluginCommand<P> {
fn name(&self) -> &str {
&self.signature.name
}
fn signature(&self) -> Signature {
self.signature.clone()
}
fn usage(&self) -> &str {
&self.signature.usage
}
async fn run(
&self,
_args: CommandArgs,
_registry: &CommandRegistry,
) -> Result<OutputStream, ShellError> {
// todo: call the plugin functions here
Ok(OutputStream::empty())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment