Struct nu_plugin::EvaluatedCall
source · pub struct EvaluatedCall {
pub head: Span,
pub positional: Vec<Value>,
pub named: Vec<(Spanned<String>, Option<Value>)>,
}
Expand description
A representation of the plugin’s invocation command including command line args
The EvaluatedCall
contains information about the way a Plugin was invoked
representing the Span
corresponding to the invocation as well as the arguments
it was invoked with. It is one of three items passed to run
along with
name
which command that was invoked and a Value
that represents the input.
The evaluated call is used with the Plugins because the plugin doesn’t have access to the Stack and the EngineState the way a built in command might. For that reason, before encoding the message to the plugin all the arguments to the original call (which are expressions) are evaluated and passed to Values
Fields§
§head: Span
Span of the command invocation
positional: Vec<Value>
Values of positional arguments
named: Vec<(Spanned<String>, Option<Value>)>
Names and values of named arguments
Implementations§
source§impl EvaluatedCall
impl EvaluatedCall
sourcepub fn has_flag(&self, flag_name: &str) -> bool
pub fn has_flag(&self, flag_name: &str) -> bool
Indicates whether named parameter is present in the arguments
Typically this method would be used on a flag parameter, a named parameter that does not take a value.
Examples
Invoked as my_command --foo
:
assert!(call.has_flag("foo"));
Invoked as my_command --bar
:
assert!(!call.has_flag("foo"));
sourcepub fn get_flag_value(&self, flag_name: &str) -> Option<Value>
pub fn get_flag_value(&self, flag_name: &str) -> Option<Value>
Returns the Value
of an optional named argument
Examples
Invoked as my_command --foo 123
:
let opt_foo = match call.get_flag_value("foo") {
Some(Value::Int { val, .. }) => Some(val),
None => None,
_ => panic!(),
};
assert_eq!(opt_foo, Some(123));
Invoked as my_command
:
let opt_foo = match call.get_flag_value("foo") {
Some(Value::Int { val, .. }) => Some(val),
None => None,
_ => panic!(),
};
assert_eq!(opt_foo, None);
sourcepub fn nth(&self, pos: usize) -> Option<Value>
pub fn nth(&self, pos: usize) -> Option<Value>
Returns the Value
of a given (zero indexed) positional argument, if present
Examples:
Invoked as my_command a b c
:
let arg = match call.nth(1) {
Some(Value::String { val, .. }) => val,
_ => panic!(),
};
assert_eq!(arg, "b".to_owned());
let arg = call.nth(7);
assert!(arg.is_none());
sourcepub fn get_flag<T: FromValue>(
&self,
name: &str
) -> Result<Option<T>, ShellError>
pub fn get_flag<T: FromValue>( &self, name: &str ) -> Result<Option<T>, ShellError>
Returns the value of a named argument interpreted as type T
Examples
Invoked as my_command --foo 123
:
let foo = call.get_flag::<i64>("foo");
assert_eq!(foo.unwrap(), Some(123));
Invoked as my_command --bar 123
:
let foo = call.get_flag::<i64>("foo");
assert_eq!(foo.unwrap(), None);
Invoked as my_command --foo abc
:
let foo = call.get_flag::<i64>("foo");
assert!(foo.is_err());
sourcepub fn rest<T: FromValue>(
&self,
starting_pos: usize
) -> Result<Vec<T>, ShellError>
pub fn rest<T: FromValue>( &self, starting_pos: usize ) -> Result<Vec<T>, ShellError>
Retrieve the Nth and all following positional arguments as type T
Example
Invoked as my_command zero one two three
:
let args = call.rest::<String>(0);
assert_eq!(args.unwrap(), vec!["zero", "one", "two", "three"]);
let args = call.rest::<String>(2);
assert_eq!(args.unwrap(), vec!["two", "three"]);
sourcepub fn opt<T: FromValue>(&self, pos: usize) -> Result<Option<T>, ShellError>
pub fn opt<T: FromValue>(&self, pos: usize) -> Result<Option<T>, ShellError>
Retrieve the value of an optional positional argument interpreted as type T
Returns the value of a (zero indexed) positional argument of type T
.
Alternatively returns None
if the positional argument does not exist
or an error that can be passed back to the shell on error.
sourcepub fn req<T: FromValue>(&self, pos: usize) -> Result<T, ShellError>
pub fn req<T: FromValue>(&self, pos: usize) -> Result<T, ShellError>
Retrieve the value of a mandatory positional argument as type T
Expect a positional argument of type T
and return its value or, if the
argument does not exist or is of the wrong type, return an error that can
be passed back to the shell.
Trait Implementations§
source§impl Clone for EvaluatedCall
impl Clone for EvaluatedCall
source§fn clone(&self) -> EvaluatedCall
fn clone(&self) -> EvaluatedCall
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for EvaluatedCall
impl Debug for EvaluatedCall
source§impl<'de> Deserialize<'de> for EvaluatedCall
impl<'de> Deserialize<'de> for EvaluatedCall
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Auto Trait Implementations§
impl !RefUnwindSafe for EvaluatedCall
impl Send for EvaluatedCall
impl Sync for EvaluatedCall
impl Unpin for EvaluatedCall
impl !UnwindSafe for EvaluatedCall
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where C: Color,
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more