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:
Hristo Filaretov
2021-08-26 19:58:53 +02:00
committed by GitHub
parent 88817a8f10
commit b8e2bdd6b1
97 changed files with 270 additions and 87 deletions

View File

@ -147,7 +147,7 @@ pub struct Signature {
/// The list of positional arguments, both required and optional, and their corresponding types and help text
pub positional: Vec<(PositionalType, Description)>,
/// After the positional arguments, a catch-all for the rest of the arguments that might follow, their type, and help text
pub rest_positional: Option<(SyntaxShape, Description)>,
pub rest_positional: Option<(String, SyntaxShape, Description)>,
/// The named flags with corresponding type and help text
pub named: IndexMap<String, (NamedType, Description)>,
/// The type of values being sent out from the command into the pipeline, if any
@ -194,7 +194,7 @@ impl Signature {
allowed.insert(shape.display());
}
if let Some((shape, _)) = &self.rest_positional {
if let Some((_, shape, _)) = &self.rest_positional {
allowed.insert(shape.display());
}
@ -348,8 +348,13 @@ impl 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
pub fn rest(mut self, ty: SyntaxShape, desc: impl Into<String>) -> Signature {
self.rest_positional = Some((ty, desc.into()));
pub fn rest(
mut self,
name: impl Into<String>,
ty: SyntaxShape,
desc: impl Into<String>,
) -> Signature {
self.rest_positional = Some((name.into(), ty, desc.into()));
self
}