forked from extern/nushell
Plugin with evaluated call (#393)
* plugin trait * impl of trait * record and absolute path * plugin example crate * clippy error * correcting cargo * evaluated call for plugin
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
use nu_plugin::plugin::PluginError;
|
||||
use nu_protocol::{Span, Value};
|
||||
use nu_protocol::{ShellError, Span, Value};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum Action {
|
||||
@ -82,14 +81,14 @@ impl Inc {
|
||||
"Usage: inc field [--major|--minor|--patch]"
|
||||
}
|
||||
|
||||
pub fn inc(&self, value: &Value) -> Result<Value, PluginError> {
|
||||
pub fn inc(&self, value: &Value) -> Result<Value, ShellError> {
|
||||
match value {
|
||||
Value::Int { val, span } => Ok(Value::Int {
|
||||
val: val + 1,
|
||||
span: *span,
|
||||
}),
|
||||
Value::String { val, .. } => Ok(self.apply(val)),
|
||||
_ => Err(PluginError::RunTimeError("incrementable value".to_string())),
|
||||
_ => Err(ShellError::InternalError("incrementable value".to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
use crate::inc::SemVerAction;
|
||||
use crate::Inc;
|
||||
use nu_plugin::{plugin::PluginError, Plugin};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::{Signature, Span, Value};
|
||||
use nu_plugin::{EvaluatedCall, Plugin};
|
||||
use nu_protocol::{ShellError, Signature, Span, Value};
|
||||
|
||||
impl Plugin for Inc {
|
||||
fn signature(&self) -> Vec<Signature> {
|
||||
@ -25,7 +24,12 @@ impl Plugin for Inc {
|
||||
)]
|
||||
}
|
||||
|
||||
fn run(&mut self, name: &str, call: &Call, input: &Value) -> Result<Value, PluginError> {
|
||||
fn run(
|
||||
&mut self,
|
||||
name: &str,
|
||||
call: &EvaluatedCall,
|
||||
input: &Value,
|
||||
) -> Result<Value, ShellError> {
|
||||
if name != "inc" {
|
||||
return Ok(Value::Nothing {
|
||||
span: Span::unknown(),
|
||||
|
Reference in New Issue
Block a user