Created
October 19, 2020 12:47
-
-
Save daschl/f655121f46c6182fdd13c13022d96765 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
//! 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