mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 01:24:58 +02:00
Allow different names for ...rest (#3954)
* Allow different names for ...rest * Resolves #3945 * This change requires an explicit name for the rest argument in `WholeStreamCommand`, which is why there are so many changed files. * Remove redundant clone * Add tests
This commit is contained in:
@ -205,7 +205,7 @@ pub fn get_documentation(
|
||||
}
|
||||
|
||||
if let Some(rest_positional) = &signature.rest_positional {
|
||||
long_desc.push_str(&format!(" ...args: {}\n", rest_positional.1));
|
||||
long_desc.push_str(&format!(" ...args: {}\n", rest_positional.2));
|
||||
}
|
||||
}
|
||||
if !signature.named.is_empty() {
|
||||
|
@ -125,7 +125,7 @@ fn get_signature(sig: &mut Signature, tag: Tag) -> Vec<Value> {
|
||||
}
|
||||
|
||||
match r {
|
||||
Some((shape, desc)) => {
|
||||
Some((rest_name, shape, desc)) => {
|
||||
let mut indexmap = IndexMap::new();
|
||||
// let output = format!("Rest|{}|{}|{}\n", name, shape.syntax_shape_name(), desc);
|
||||
// eprintln!("{}", output);
|
||||
@ -136,7 +136,7 @@ fn get_signature(sig: &mut Signature, tag: Tag) -> Vec<Value> {
|
||||
);
|
||||
indexmap.insert(
|
||||
"parameter_name".to_string(),
|
||||
UntaggedValue::string("".to_string()).into_value(&tag),
|
||||
UntaggedValue::string(rest_name.to_string()).into_value(&tag),
|
||||
);
|
||||
indexmap.insert(
|
||||
"parameter_type".to_string(),
|
||||
|
@ -468,7 +468,10 @@ impl VarSyntaxShapeDeductor {
|
||||
if let Expression::Variable(var_name, _) = &positional.expr {
|
||||
let deduced_shape = {
|
||||
if pos_idx >= signature.positional.len() {
|
||||
signature.rest_positional.as_ref().map(|(shape, _)| shape)
|
||||
signature
|
||||
.rest_positional
|
||||
.as_ref()
|
||||
.map(|(_, shape, _)| shape)
|
||||
} else {
|
||||
match &signature.positional[pos_idx].0 {
|
||||
PositionalType::Mandatory(_, shape)
|
||||
|
@ -139,7 +139,7 @@ impl WholeStreamCommand for Arc<Block> {
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
if block.params.rest_positional.is_some() {
|
||||
if let Some(rest_pos) = &block.params.rest_positional {
|
||||
let elements: Vec<_> = args_iter.collect();
|
||||
let start = if let Some(first) = elements.first() {
|
||||
first.tag.span.start()
|
||||
@ -153,15 +153,15 @@ impl WholeStreamCommand for Arc<Block> {
|
||||
};
|
||||
|
||||
ctx.scope.add_var(
|
||||
"$rest",
|
||||
format!("${}", rest_pos.0),
|
||||
UntaggedValue::Table(elements).into_value(Span::new(start, end)),
|
||||
);
|
||||
}
|
||||
} else if block.params.rest_positional.is_some() {
|
||||
} else if let Some(rest_pos) = &block.params.rest_positional {
|
||||
//If there is a rest arg, but no args were provided,
|
||||
//we have to set $rest to an empty table
|
||||
ctx.scope.add_var(
|
||||
"$rest",
|
||||
format!("${}", rest_pos.0),
|
||||
UntaggedValue::Table(Vec::new()).into_value(Span::new(0, 0)),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user