Relax groups and blocks to output at pipeline level (#3643)

* Relax groups and blocks to output at pipeline level

* Fix up tests and add ignore command
This commit is contained in:
JT
2021-06-18 13:04:51 +12:00
committed by GitHub
parent d9d956e54f
commit fe5055cf29
11 changed files with 177 additions and 107 deletions

View File

@ -25,62 +25,64 @@ pub fn run_block(
let num_groups = block.block.len();
for (group_num, group) in block.block.iter().enumerate() {
match output {
Ok(inp) if inp.is_empty() => {}
Ok(inp) => {
// Run autoview on the values we've seen so far
// We may want to make this configurable for other kinds of hosting
if let Some(autoview) = ctx.get_command("autoview") {
let mut output_stream = match ctx.run_command(
autoview,
Tag::unknown(),
Call::new(
Box::new(SpannedExpression::new(
Expression::Synthetic(Synthetic::String("autoview".into())),
Span::unknown(),
)),
Span::unknown(),
),
inp,
) {
Ok(x) => x,
Err(e) => {
return Err(e);
}
};
match output_stream.next() {
Some(Value {
value: UntaggedValue::Error(e),
..
}) => {
return Err(e);
}
Some(_item) => {
if let Some(err) = ctx.get_errors().get(0) {
ctx.clear_errors();
return Err(err.clone());
}
if ctx.ctrl_c().load(Ordering::SeqCst) {
return Ok(InputStream::empty());
}
}
None => {
if let Some(err) = ctx.get_errors().get(0) {
ctx.clear_errors();
return Err(err.clone());
}
}
}
}
}
Err(e) => {
return Err(e);
}
}
output = Ok(OutputStream::empty());
let num_pipelines = group.pipelines.len();
for (pipeline_num, pipeline) in group.pipelines.iter().enumerate() {
match output {
Ok(inp) if inp.is_empty() => {}
Ok(inp) => {
// Run autoview on the values we've seen so far
// We may want to make this configurable for other kinds of hosting
if let Some(autoview) = ctx.get_command("autoview") {
let mut output_stream = match ctx.run_command(
autoview,
Tag::unknown(),
Call::new(
Box::new(SpannedExpression::new(
Expression::Synthetic(Synthetic::String("autoview".into())),
Span::unknown(),
)),
Span::unknown(),
),
inp,
) {
Ok(x) => x,
Err(e) => {
return Err(e);
}
};
match output_stream.next() {
Some(Value {
value: UntaggedValue::Error(e),
..
}) => {
return Err(e);
}
Some(_item) => {
if let Some(err) = ctx.get_errors().get(0) {
ctx.clear_errors();
return Err(err.clone());
}
if ctx.ctrl_c().load(Ordering::SeqCst) {
return Ok(InputStream::empty());
}
}
None => {
if let Some(err) = ctx.get_errors().get(0) {
ctx.clear_errors();
return Err(err.clone());
}
}
}
} else {
let _: Vec<_> = inp.collect();
}
}
Err(e) => {
return Err(e);
}
}
output = Ok(OutputStream::empty());
match output {
Ok(inp) if inp.is_empty() => {}
Ok(mut output_stream) => {
@ -122,7 +124,7 @@ pub fn run_block(
run_pipeline(pipeline, ctx, input, external_redirection)
} else {
// otherwise, we're in the middle of the block, so use a default redirection
run_pipeline(pipeline, ctx, input, ExternalRedirection::Stdout)
run_pipeline(pipeline, ctx, input, ExternalRedirection::None)
};
input = OutputStream::empty();