mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 23:02:28 +02:00
parser/add rest args to def (#2961)
* Add rest arg to def This commit applied adds the ability to define the rest parameter of a def command. It does not implement the functionality to expand the rest argument in a user defined def function. The rest argument has to be exactly worded "...rest". Example after this PR is applied: file test.nu ```shell def my_command [ ...rest:int # My rest arg ] { echo 1 2 3 } ``` ```shell > source test.nu > my_command -h Usage: > my_command ...args {flags} Parameters: ...args: My rest arg Flags: -h, --help: Display this help message ``` * Fix space in help on wrong side
This commit is contained in:
@ -48,14 +48,18 @@ impl Spanned<String> {
|
||||
) -> impl Iterator<Item = &'a str> {
|
||||
items.map(|item| &item.item[..])
|
||||
}
|
||||
}
|
||||
|
||||
impl Spanned<String> {
|
||||
/// Borrows the contained String
|
||||
pub fn borrow_spanned(&self) -> Spanned<&str> {
|
||||
let span = self.span;
|
||||
self.item[..].spanned(span)
|
||||
}
|
||||
|
||||
pub fn slice_spanned(&self, span: impl Into<Span>) -> Spanned<&str> {
|
||||
let span = span.into();
|
||||
let item = &self.item[span.start()..span.end()];
|
||||
item.spanned(span)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SpannedItem: Sized {
|
||||
|
Reference in New Issue
Block a user