Struct nu_protocol::Signature[][src]

pub struct Signature {
    pub name: String,
    pub usage: String,
    pub positional: Vec<(PositionalType, String)>,
    pub rest_positional: Option<(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
Expand description

The name of the command. Used when calling the command

usage: String
Expand description

Usage instructions about the command

positional: Vec<(PositionalType, String)>
Expand description

The list of positional arguments, both required and optional, and their corresponding types and help text

rest_positional: Option<(SyntaxShape, String)>
Expand description

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)>
Expand description

The named flags with corresponding type and help text

yields: Option<Type>
Expand description

The type of values being sent out from the command into the pipeline, if any

input: Option<Type>
Expand description

The type of values being read in from the pipeline into the command, if any

is_filter: bool
Expand description

If the command is expected to filter data, or to consume it (as a sink)

Implementations

impl Signature[src]

pub fn shift_positional(&mut self)[src]

pub fn remove_named(&mut self, name: &str)[src]

pub fn allowed(&self) -> Vec<String>[src]

impl Signature[src]

pub fn new(name: impl Into<String>) -> Signature[src]

Create a new command signature with the given name

pub fn build(name: impl Into<String>) -> Signature[src]

Create a new signature

pub fn desc(self, usage: impl Into<String>) -> Signature[src]

Add a description to the signature

pub fn required(
    self,
    name: impl Into<String>,
    ty: impl Into<SyntaxShape>,
    desc: impl Into<String>
) -> Signature
[src]

Add a required positional argument to the signature

pub fn optional(
    self,
    name: impl Into<String>,
    ty: impl Into<SyntaxShape>,
    desc: impl Into<String>
) -> Signature
[src]

Add an optional positional argument to the signature

pub fn named(
    self,
    name: impl Into<String>,
    ty: impl Into<SyntaxShape>,
    desc: impl Into<String>,
    short: Option<char>
) -> Signature
[src]

Add an optional named flag argument to the signature

pub fn required_named(
    self,
    name: impl Into<String>,
    ty: impl Into<SyntaxShape>,
    desc: impl Into<String>,
    short: Option<char>
) -> Signature
[src]

Add a required named flag argument to the signature

pub fn switch(
    self,
    name: impl Into<String>,
    desc: impl Into<String>,
    short: Option<char>
) -> Signature
[src]

Add a switch to the signature

pub fn filter(self) -> Signature[src]

Set the filter flag for the signature

pub fn rest(self, ty: SyntaxShape, desc: impl Into<String>) -> Signature[src]

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

pub fn yields(self, ty: Type) -> Signature[src]

Add a type for the output of the command to the signature

pub fn input(self, ty: Type) -> Signature[src]

Add a type for the input of the command to the signature

pub fn get_shorts(&self) -> Vec<char>[src]

Get list of the short-hand flags

Trait Implementations

impl Clone for Signature[src]

fn clone(&self) -> Signature[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Signature[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<'de> Deserialize<'de> for Signature[src]

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl PartialEq<Signature> for Signature[src]

fn eq(&self, other: &Self) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl PrettyDebugWithSource for Signature[src]

fn pretty_debug(&self, source: &str) -> DebugDocBuilder[src]

Prepare a Signature for pretty-printing

fn refined_pretty_debug(
    &self,
    _refine: PrettyDebugRefineKind,
    source: &str
) -> DebugDocBuilder
[src]

fn debug(&self, source: impl Into<Text>) -> String where
    Self: Clone
[src]

fn debuggable(self, source: impl Into<Text>) -> DebuggableWithSource<Self>[src]

impl Serialize for Signature[src]

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
    __S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

impl Eq for Signature[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

pub fn equivalent(&self, key: &K) -> bool[src]

Compare self to key and return true if they are equal.

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> SpannedItem for T[src]

fn spanned(self, span: impl Into<Span>) -> Spanned<Self>[src]

Converts a value into a Spanned value

fn spanned_unknown(self) -> Spanned<Self>[src]

Converts a value into a Spanned value, using an unknown Span

impl<T> TaggedItem for T[src]

fn tagged(self, tag: impl Into<Tag>) -> Tagged<Self>[src]

fn tagged_unknown(self) -> Tagged<Self>[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]