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) -> Result<bool, ShellError>
pub fn has_flag(&self, flag_name: &str) -> Result<bool, ShellError>
Check if a flag (named parameter that does not take a value) is set Returns Ok(true) if flag is set or passed true value Returns Ok(false) if flag is not set or passed false value Returns Err if passed value is not a boolean
§Examples
Invoked as my_command --foo
:
assert!(call.has_flag("foo").unwrap());
Invoked as my_command --bar
:
assert!(!call.has_flag("foo").unwrap());
Invoked as my_command --foo=true
:
assert!(call.has_flag("foo").unwrap());
Invoked as my_command --foo=false
:
assert!(!call.has_flag("foo").unwrap());
Invoked with wrong type as my_command --foo=1
:
assert!(call.has_flag("foo").is_err());
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
source§impl<T> IntoSpanned for T
impl<T> IntoSpanned for T
source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
source§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 moresource§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