Add helper functions

This commit is contained in:
Ian Manske 2024-07-14 10:51:20 -07:00
parent 3d1145e759
commit 8dfa500c80
2 changed files with 32 additions and 0 deletions

View File

@ -635,6 +635,34 @@ impl PipelineData {
Ok(None)
}
}
pub fn unsupported_input_error(
self,
expected_type: impl Into<String>,
span: Span,
) -> ShellError {
match self {
PipelineData::Empty => ShellError::PipelineEmpty { dst_span: span },
PipelineData::Value(value, ..) => ShellError::OnlySupportsThisInputType {
exp_input_type: expected_type.into(),
wrong_type: value.get_type().get_non_specified_string(),
dst_span: span,
src_span: value.span(),
},
PipelineData::ListStream(stream, ..) => ShellError::OnlySupportsThisInputType {
exp_input_type: expected_type.into(),
wrong_type: "list (stream)".into(),
dst_span: span,
src_span: stream.span(),
},
PipelineData::ByteStream(stream, ..) => ShellError::OnlySupportsThisInputType {
exp_input_type: expected_type.into(),
wrong_type: stream.type_().describe().into(),
dst_span: span,
src_span: stream.span(),
},
}
}
}
enum PipelineIteratorInner {

View File

@ -36,6 +36,10 @@ pub enum Type {
}
impl Type {
pub fn list(inner: Type) -> Self {
Self::List(Box::new(inner))
}
pub fn record() -> Self {
Self::Record([].into())
}