forked from extern/nushell
Stdout/Stderr redirection (#7185)
This adds new pipeline connectors called out> and err> which redirect either stdout or stderr to a file. You can also use out+err> (or err+out>) to redirect both streams into a file.
This commit is contained in:
@@ -32,6 +32,10 @@ pub enum FlatShape {
|
||||
GlobPattern,
|
||||
Variable,
|
||||
Flag,
|
||||
Pipe,
|
||||
And,
|
||||
Or,
|
||||
Redirection,
|
||||
Custom(DeclId),
|
||||
}
|
||||
|
||||
@@ -63,6 +67,10 @@ impl Display for FlatShape {
|
||||
FlatShape::GlobPattern => write!(f, "shape_globpattern"),
|
||||
FlatShape::Variable => write!(f, "shape_variable"),
|
||||
FlatShape::Flag => write!(f, "shape_flag"),
|
||||
FlatShape::Pipe => write!(f, "shape_pipe"),
|
||||
FlatShape::And => write!(f, "shape_and"),
|
||||
FlatShape::Or => write!(f, "shape_or"),
|
||||
FlatShape::Redirection => write!(f, "shape_redirection"),
|
||||
FlatShape::Custom(_) => write!(f, "shape_custom"),
|
||||
}
|
||||
}
|
||||
@@ -502,10 +510,30 @@ pub fn flatten_pipeline_element(
|
||||
pipeline_element: &PipelineElement,
|
||||
) -> Vec<(Span, FlatShape)> {
|
||||
match pipeline_element {
|
||||
PipelineElement::Expression(expr)
|
||||
| PipelineElement::Redirect(expr)
|
||||
| PipelineElement::And(expr)
|
||||
| PipelineElement::Or(expr) => flatten_expression(working_set, expr),
|
||||
PipelineElement::Expression(span, expr) => {
|
||||
if let Some(span) = span {
|
||||
let mut output = vec![(*span, FlatShape::Pipe)];
|
||||
output.append(&mut flatten_expression(working_set, expr));
|
||||
output
|
||||
} else {
|
||||
flatten_expression(working_set, expr)
|
||||
}
|
||||
}
|
||||
PipelineElement::Redirection(span, _, expr) => {
|
||||
let mut output = vec![(*span, FlatShape::Redirection)];
|
||||
output.append(&mut flatten_expression(working_set, expr));
|
||||
output
|
||||
}
|
||||
PipelineElement::And(span, expr) => {
|
||||
let mut output = vec![(*span, FlatShape::And)];
|
||||
output.append(&mut flatten_expression(working_set, expr));
|
||||
output
|
||||
}
|
||||
PipelineElement::Or(span, expr) => {
|
||||
let mut output = vec![(*span, FlatShape::Or)];
|
||||
output.append(&mut flatten_expression(working_set, expr));
|
||||
output
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user