Struct nu_protocol::Signature
source · [−]pub struct Signature {
pub name: String,
pub usage: String,
pub extra_usage: String,
pub positional: Vec<(PositionalType, String)>,
pub rest_positional: Option<(String, SyntaxShape, String)>,
pub named: IndexMap<String, (NamedType, String)>,
pub yields: Option<Type>,
pub input: Option<Type>,
pub is_filter: bool,
}
Expand description
The full signature of a command. All commands have a signature similar to a function signature. Commands will use this information to register themselves with Nu’s core engine so that the command can be invoked, help can be displayed, and calls to the command can be error-checked.
Fields
name: String
The name of the command. Used when calling the command
usage: String
Usage instructions about the command
extra_usage: String
Longer or more verbose usage statement
positional: Vec<(PositionalType, String)>
The list of positional arguments, both required and optional, and their corresponding types and help text
rest_positional: Option<(String, SyntaxShape, String)>
After the positional arguments, a catch-all for the rest of the arguments that might follow, their type, and help text
named: IndexMap<String, (NamedType, String)>
The named flags with corresponding type and help text
yields: Option<Type>
The type of values being sent out from the command into the pipeline, if any
input: Option<Type>
The type of values being read in from the pipeline into the command, if any
is_filter: bool
If the command is expected to filter data, or to consume it (as a sink)
Implementations
sourceimpl Signature
impl Signature
sourcepub fn new(name: impl Into<String>) -> Signature
pub fn new(name: impl Into<String>) -> Signature
Create a new command signature with the given name
sourcepub fn required(
self,
name: impl Into<String>,
ty: impl Into<SyntaxShape>,
desc: impl Into<String>
) -> Signature
pub fn required(
self,
name: impl Into<String>,
ty: impl Into<SyntaxShape>,
desc: impl Into<String>
) -> Signature
Add a required positional argument to the signature
sourcepub fn optional(
self,
name: impl Into<String>,
ty: impl Into<SyntaxShape>,
desc: impl Into<String>
) -> Signature
pub fn optional(
self,
name: impl Into<String>,
ty: impl Into<SyntaxShape>,
desc: impl Into<String>
) -> Signature
Add an optional positional argument to the signature
sourcepub fn named(
self,
name: impl Into<String>,
ty: impl Into<SyntaxShape>,
desc: impl Into<String>,
short: Option<char>
) -> Signature
pub fn named(
self,
name: impl Into<String>,
ty: impl Into<SyntaxShape>,
desc: impl Into<String>,
short: Option<char>
) -> Signature
Add an optional named flag argument to the signature
sourcepub fn required_named(
self,
name: impl Into<String>,
ty: impl Into<SyntaxShape>,
desc: impl Into<String>,
short: Option<char>
) -> Signature
pub fn required_named(
self,
name: impl Into<String>,
ty: impl Into<SyntaxShape>,
desc: impl Into<String>,
short: Option<char>
) -> Signature
Add a required named flag argument to the signature
sourcepub fn switch(
self,
name: impl Into<String>,
desc: impl Into<String>,
short: Option<char>
) -> Signature
pub fn switch(
self,
name: impl Into<String>,
desc: impl Into<String>,
short: Option<char>
) -> Signature
Add a switch to the signature
sourcepub fn rest(
self,
name: impl Into<String>,
ty: SyntaxShape,
desc: impl Into<String>
) -> Signature
pub fn rest(
self,
name: impl Into<String>,
ty: SyntaxShape,
desc: impl Into<String>
) -> Signature
Set the type for the “rest” of the positional arguments Note: Not naming the field in your struct holding the rest values “rest”, can cause errors when deserializing
sourcepub fn yields(self, ty: Type) -> Signature
pub fn yields(self, ty: Type) -> Signature
Add a type for the output of the command to the signature
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Signature
impl<'de> Deserialize<'de> for Signature
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl PrettyDebugWithSource for Signature
impl PrettyDebugWithSource for Signature
sourcefn pretty_debug(&self, source: &str) -> DebugDocBuilder
fn pretty_debug(&self, source: &str) -> DebugDocBuilder
Prepare a Signature for pretty-printing
fn refined_pretty_debug(
&self,
_refine: PrettyDebugRefineKind,
source: &str
) -> DebugDocBuilder
fn debug(&self, source: impl Into<Text>) -> String where
Self: Clone,
fn debuggable(self, source: impl Into<Text>) -> DebuggableWithSource<Self>
impl Eq for Signature
Auto Trait Implementations
impl RefUnwindSafe for Signature
impl Send for Signature
impl Sync for Signature
impl Unpin for Signature
impl UnwindSafe for Signature
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcepub fn equivalent(&self, key: &K) -> bool
pub fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> SpannedItem for T
impl<T> SpannedItem for T
sourceimpl<T> TaggedItem for T
impl<T> TaggedItem for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more