diff --git a/src/lib.rs b/src/lib.rs index 521b85b..f637e08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,60 +9,14 @@ mod tui; use anyhow::{Context, Result}; -use nu_plugin::{EvaluatedCall, LabeledError, Plugin}; -use nu_protocol::{Category, PluginExample, PluginSignature, Type, Value}; -use nu_protocol::{Span, SyntaxShape}; +use nu_plugin::{EvaluatedCall, LabeledError}; +use nu_protocol::{Span, Value}; use app::{Mode, State}; use config::Config; use terminal::restore as restore_terminal; use terminal::setup as setup_terminal; -/// the main structure of the [Nushell](https://nushell.sh) plugin -pub struct Explore; - -impl Plugin for Explore { - fn signature(&self) -> Vec { - vec![PluginSignature::build("explore") - .usage("interactively explore Nushell structured data") - .input_output_type(Type::Any, Type::Any) - .optional( - "config", - SyntaxShape::Record(vec![]), - "a config record to configure everything in explore", - ) - .plugin_examples(vec![ - PluginExample { - example: "open Cargo.toml | explore".into(), - description: "explore the Cargo.toml file of this project".into(), - result: None, - }, - PluginExample { - example: r#"$nu | explore {show_cell_path: false, layout: "compact"}"#.into(), - description: "explore `$nu` and set some config options".into(), - result: None, - }, - ]) - .category(Category::Experimental)] - } - - fn run( - &mut self, - name: &str, - call: &EvaluatedCall, - input: &Value, - ) -> Result { - match name { - "explore" => explore(call, input), - _ => Err(LabeledError { - label: "Plugin call with wrong name signature".into(), - msg: "the signature used to call the plugin does not match any name in the plugin signature vector".into(), - span: Some(call.head), - }), - } - } -} - /// the entry point of the `explore` command /// /// this function @@ -70,7 +24,7 @@ impl Plugin for Explore { /// 1. sets the terminal up (see [`terminal::setup`]) /// 1. runs the application (see [`app::run`]) /// 1. restores the terminal (see [`terminal::restore`]) -fn explore(call: &EvaluatedCall, input: &Value) -> Result { +pub fn explore(call: &EvaluatedCall, input: &Value) -> Result { let config = Config::from_value(call.opt(0).unwrap().unwrap_or(Value::record( vec![], vec![], diff --git a/src/main.rs b/src/main.rs index c9716ff..7d294d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,51 @@ -use nu_plugin::{serve_plugin, MsgPackSerializer}; -use nu_plugin_explore::Explore; +use nu_plugin::{serve_plugin, EvaluatedCall, LabeledError, MsgPackSerializer, Plugin}; +use nu_plugin_explore::explore; +use nu_protocol::{Category, PluginExample, PluginSignature, SyntaxShape, Type, Value}; + +/// the main structure of the [Nushell](https://nushell.sh) plugin +struct Explore; + +impl Plugin for Explore { + fn signature(&self) -> Vec { + vec![PluginSignature::build("explore") + .usage("interactively explore Nushell structured data") + .input_output_type(Type::Any, Type::Any) + .optional( + "config", + SyntaxShape::Record(vec![]), + "a config record to configure everything in explore", + ) + .plugin_examples(vec![ + PluginExample { + example: "open Cargo.toml | explore".into(), + description: "explore the Cargo.toml file of this project".into(), + result: None, + }, + PluginExample { + example: r#"$nu | explore {show_cell_path: false, layout: "compact"}"#.into(), + description: "explore `$nu` and set some config options".into(), + result: None, + }, + ]) + .category(Category::Experimental)] + } + + fn run( + &mut self, + name: &str, + call: &EvaluatedCall, + input: &Value, + ) -> Result { + match name { + "explore" => explore(call, input), + _ => Err(LabeledError { + label: "Plugin call with wrong name signature".into(), + msg: "the signature used to call the plugin does not match any name in the plugin signature vector".into(), + span: Some(call.head), + }), + } + } +} fn main() { serve_plugin(&mut Explore {}, MsgPackSerializer {})