2019-07-15 23:16:27 +02:00
|
|
|
#[doc(hidden)]
|
2019-07-03 22:31:15 +02:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! command {
|
|
|
|
(
|
|
|
|
Named { $export:tt $args:ident $body:block }
|
|
|
|
Positional { $($number:tt)* }
|
|
|
|
Rest {}
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name:tt,
|
|
|
|
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
|
|
|
|
optional_positional: vec![ $($optional_positional:tt)* ],
|
|
|
|
rest_positional: $rest_positional:tt,
|
|
|
|
named: {
|
|
|
|
$(
|
2019-07-15 23:16:27 +02:00
|
|
|
($named_param:tt : $named_type:ty : $named_kind:tt)
|
2019-07-03 22:31:15 +02:00
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function {
|
|
|
|
$( ( $param_name:tt : $param_type:tt ) )*
|
|
|
|
}
|
|
|
|
|
|
|
|
Extract {
|
|
|
|
$($extract:tt)*
|
|
|
|
}
|
|
|
|
) => {
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
pub struct $export;
|
|
|
|
|
|
|
|
impl Command for $export {
|
2020-12-18 08:53:49 +01:00
|
|
|
fn run(&self, $args: CommandArgs) -> Result<OutputStream, ShellError> {
|
2019-07-24 00:22:11 +02:00
|
|
|
fn command($args: EvaluatedCommandArgs, ( $($param_name),*, ): ( $($param_type),*, )) -> Result<OutputStream, ShellError> {
|
2019-07-03 22:31:15 +02:00
|
|
|
let output = $body;
|
|
|
|
|
2021-04-12 04:35:01 +02:00
|
|
|
Ok(output.to_action_stream())
|
2019-07-03 22:31:15 +02:00
|
|
|
}
|
|
|
|
|
2019-07-24 00:22:11 +02:00
|
|
|
let $args = $args.evaluate_once(registry)?;
|
2019-07-15 23:16:27 +02:00
|
|
|
let tuple = ( $($extract ,)* );
|
2019-07-03 22:31:15 +02:00
|
|
|
command( $args, tuple )
|
|
|
|
}
|
|
|
|
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
stringify!($config_name)
|
|
|
|
}
|
|
|
|
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
fn config(&self) -> $nu_parser::registry::Signature {
|
|
|
|
$nu_parser::registry::Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: self.name().to_string(),
|
|
|
|
positional: vec![$($mandatory_positional)*],
|
|
|
|
rest_positional: false,
|
2019-07-13 04:07:06 +02:00
|
|
|
is_filter: false,
|
|
|
|
is_sink: false,
|
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
named: {
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
use $nu_parser::registry::NamedType;
|
2019-07-03 22:31:15 +02:00
|
|
|
|
|
|
|
#[allow(unused_mut)]
|
|
|
|
let mut named: indexmap::IndexMap<String, NamedType> = indexmap::IndexMap::new();
|
|
|
|
|
|
|
|
$(
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
named.insert(stringify!($named_param).to_string(), $nu_parser::registry::NamedType::$named_kind);
|
2019-07-03 22:31:15 +02:00
|
|
|
)*
|
|
|
|
|
|
|
|
named
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// switch
|
|
|
|
(
|
|
|
|
Named { $export:tt $args:ident $body:block }
|
|
|
|
Positional { $($positional_count:tt)* }
|
2019-07-15 23:16:27 +02:00
|
|
|
Rest { -- $param_name:ident : Switch , $($rest:tt)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name:tt,
|
|
|
|
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
|
|
|
|
optional_positional: vec![ $($optional_positional:tt)* ],
|
|
|
|
rest_positional: $rest_positional:tt,
|
|
|
|
named: {
|
|
|
|
$($config_named:tt)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Function {
|
|
|
|
$($function:tt)*
|
|
|
|
}
|
|
|
|
Extract {
|
|
|
|
$($extract:tt)*
|
|
|
|
}
|
|
|
|
) => {
|
|
|
|
command!(
|
|
|
|
Named { $export $args $body }
|
|
|
|
Positional { $($positional_count)* + 1 }
|
|
|
|
Rest { $($rest)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name,
|
|
|
|
mandatory_positional: vec![ $($mandatory_positional)* ],
|
|
|
|
optional_positional: vec![ $($optional_positional)* ],
|
|
|
|
rest_positional: $rest_positional,
|
|
|
|
named: {
|
|
|
|
$($config_named)*
|
2019-07-15 23:16:27 +02:00
|
|
|
($param_name : Switch : Switch)
|
2019-07-03 22:31:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function {
|
|
|
|
$($function)* ($param_name : Switch)
|
|
|
|
}
|
|
|
|
|
|
|
|
Extract {
|
2019-07-15 23:16:27 +02:00
|
|
|
$($extract)* {
|
2019-07-03 22:31:15 +02:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2019-12-31 08:36:08 +01:00
|
|
|
$args.get(stringify!($param_name)).try_into()?
|
2019-07-15 23:16:27 +02:00
|
|
|
}
|
2019-07-03 22:31:15 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// mandatory named arguments
|
|
|
|
(
|
|
|
|
Named { $export:tt $args:ident $body:block }
|
|
|
|
Positional { $($positional_count:tt)* }
|
2019-07-15 23:16:27 +02:00
|
|
|
Rest { -- $param_name:ident : $param_kind:ty , $($rest:tt)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name:tt,
|
|
|
|
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
|
|
|
|
optional_positional: vec![ $($optional_positional:tt)* ],
|
|
|
|
rest_positional: $rest_positional:tt,
|
|
|
|
named: {
|
|
|
|
$($config_named:tt)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Function {
|
|
|
|
$($function:tt)*
|
|
|
|
}
|
|
|
|
Extract {
|
|
|
|
$($extract:tt)*
|
|
|
|
}
|
|
|
|
) => {
|
|
|
|
command!(
|
|
|
|
Named { $export $args $body }
|
|
|
|
Positional { $($positional_count)* + 1 }
|
|
|
|
Rest { $($rest)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name,
|
|
|
|
mandatory_positional: vec![ $($mandatory_positional)* ],
|
|
|
|
optional_positional: vec![ $($optional_positional)* ],
|
|
|
|
rest_positional: $rest_positional,
|
|
|
|
named: {
|
|
|
|
$($config_named)*
|
|
|
|
($param_name : Mandatory(NamedValue::Single))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function {
|
|
|
|
$($function)* ($param_name : $param_kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
Extract {
|
2019-07-15 23:16:27 +02:00
|
|
|
$($extract)* {
|
2019-07-03 22:31:15 +02:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2019-12-31 08:36:08 +01:00
|
|
|
$args.get(stringify!($param_name)).try_into()?
|
2019-07-15 23:16:27 +02:00
|
|
|
}
|
2019-07-03 22:31:15 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// optional named arguments
|
|
|
|
(
|
|
|
|
Named { $export:tt $args:ident $body:block }
|
|
|
|
Positional { $($positional_count:tt)* }
|
2019-07-15 23:16:27 +02:00
|
|
|
Rest { -- $param_name:ident ? : $param_kind:ty , $($rest:tt)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name:tt,
|
|
|
|
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
|
|
|
|
optional_positional: vec![ $($optional_positional:tt)* ],
|
|
|
|
rest_positional: $rest_positional:tt,
|
|
|
|
named: {
|
|
|
|
$($config_named:tt)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Function {
|
|
|
|
$($function:tt)*
|
|
|
|
}
|
|
|
|
Extract {
|
|
|
|
$($extract:tt)*
|
|
|
|
}
|
|
|
|
) => {
|
|
|
|
command!(
|
|
|
|
Named { $export $args $body }
|
|
|
|
Positional { $($positional_count)* + 1 }
|
|
|
|
Rest { $($rest)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name,
|
|
|
|
mandatory_positional: vec![ $($mandatory_positional)* ],
|
|
|
|
optional_positional: vec![ $($optional_positional)* ],
|
|
|
|
rest_positional: $rest_positional,
|
|
|
|
named: {
|
|
|
|
$($config_named)*
|
|
|
|
($param_name : Optional(NamedValue::Single))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function {
|
|
|
|
$($function)* ($param_name : $param_kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
Extract {
|
2019-07-15 23:16:27 +02:00
|
|
|
$($extract)* {
|
2019-07-03 22:31:15 +02:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2019-12-31 08:36:08 +01:00
|
|
|
$args.get(stringify!($param_name)).try_into()?
|
2019-07-15 23:16:27 +02:00
|
|
|
}
|
2019-07-03 22:31:15 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-07-12 21:22:08 +02:00
|
|
|
// mandatory positional block
|
|
|
|
(
|
|
|
|
Named { $export:ident $args:ident $body:block }
|
|
|
|
Positional { $($positional_count:tt)* }
|
2019-07-15 23:16:27 +02:00
|
|
|
Rest { $param_name:ident : Block , $($rest:tt)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-12 21:22:08 +02:00
|
|
|
name: $config_name:tt,
|
|
|
|
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
|
|
|
|
optional_positional: vec![ $($optional_positional:tt)* ],
|
|
|
|
rest_positional: $rest_positional:tt,
|
|
|
|
named: {
|
|
|
|
$($config_named:tt)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function {
|
|
|
|
$($function:tt)*
|
|
|
|
}
|
|
|
|
|
|
|
|
Extract {
|
|
|
|
$($extract:tt)*
|
|
|
|
}
|
|
|
|
|
|
|
|
) => {
|
|
|
|
command!(
|
|
|
|
Named { $export $args $body }
|
|
|
|
Positional { $($positional_count)* + 1 }
|
|
|
|
Rest { $($rest)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-12 21:22:08 +02:00
|
|
|
name: $config_name,
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory_block(
|
2019-07-12 21:22:08 +02:00
|
|
|
stringify!($param_name)
|
|
|
|
), ],
|
|
|
|
optional_positional: vec![ $($optional_positional)* ],
|
|
|
|
rest_positional: $rest_positional,
|
|
|
|
named: {
|
|
|
|
$($config_named)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function {
|
|
|
|
$($function)* ($param_name : Block)
|
|
|
|
}
|
|
|
|
|
|
|
|
Extract {
|
|
|
|
$($extract:tt)* {
|
2020-08-18 09:00:02 +02:00
|
|
|
use $nu_data::types::ExtractType;
|
2019-07-12 21:22:08 +02:00
|
|
|
let value = $args.expect_nth($($positional_count)*)?;
|
|
|
|
Block::extract(value)?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-07-03 22:31:15 +02:00
|
|
|
// mandatory positional argument
|
|
|
|
(
|
|
|
|
Named { $export:ident $args:ident $body:block }
|
|
|
|
Positional { $($positional_count:tt)* }
|
2019-07-15 23:16:27 +02:00
|
|
|
Rest { $param_name:ident : $param_kind:ty , $($rest:tt)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name:tt,
|
|
|
|
mandatory_positional: vec![ $($mandatory_positional:tt)* ],
|
|
|
|
optional_positional: vec![ $($optional_positional:tt)* ],
|
|
|
|
rest_positional: $rest_positional:tt,
|
|
|
|
named: {
|
|
|
|
$($config_named:tt)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function {
|
|
|
|
$($function:tt)*
|
|
|
|
}
|
|
|
|
|
|
|
|
Extract {
|
|
|
|
$($extract:tt)*
|
|
|
|
}
|
|
|
|
|
|
|
|
) => {
|
|
|
|
command!(
|
|
|
|
Named { $export $args $body }
|
|
|
|
Positional { $($positional_count)* + 1 }
|
|
|
|
Rest { $($rest)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name,
|
Extract core stuff into own crates
This commit extracts five new crates:
- nu-source, which contains the core source-code handling logic in Nu,
including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
conveniences
- nu-textview, which is the textview plugin extracted into a crate
One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).
This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-11-26 03:30:48 +01:00
|
|
|
mandatory_positional: vec![ $($mandatory_positional)* $nu_parser::registry::PositionalType::mandatory(
|
2019-07-15 23:16:27 +02:00
|
|
|
stringify!($param_name), <$param_kind>::syntax_type()
|
2019-07-03 22:31:15 +02:00
|
|
|
), ],
|
|
|
|
optional_positional: vec![ $($optional_positional)* ],
|
|
|
|
rest_positional: $rest_positional,
|
|
|
|
named: {
|
|
|
|
$($config_named)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function {
|
|
|
|
$($function)* ($param_name : $param_kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
Extract {
|
|
|
|
$($extract:tt)* {
|
2020-08-18 09:00:02 +02:00
|
|
|
use $nu_data::types::ExtractType;
|
2019-07-06 00:08:58 +02:00
|
|
|
let value = $args.expect_nth($($positional_count)*)?;
|
2019-07-15 23:16:27 +02:00
|
|
|
<$param_kind>::extract(&value)?
|
2019-07-03 22:31:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-07-15 23:16:27 +02:00
|
|
|
($export:ident as $config_name:tt ( $args:ident , $($command_rest:tt)* ) $body:block) => {
|
2019-07-03 22:31:15 +02:00
|
|
|
command!(
|
|
|
|
Named { $export $args $body }
|
|
|
|
Positional { 0 }
|
|
|
|
Rest { $($command_rest)* }
|
2019-08-02 21:15:07 +02:00
|
|
|
Signature {
|
2019-07-03 22:31:15 +02:00
|
|
|
name: $config_name,
|
|
|
|
mandatory_positional: vec![],
|
|
|
|
optional_positional: vec![],
|
|
|
|
rest_positional: false,
|
|
|
|
named: {}
|
|
|
|
}
|
|
|
|
|
|
|
|
Function {
|
|
|
|
}
|
|
|
|
|
|
|
|
Extract {
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|