Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve empty pipelines #7383

Merged
merged 2 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix tests and eval
  • Loading branch information
sophiajt committed Dec 7, 2022
commit e1a488c764347cebeb0249a3a69a95d2c200452a
4 changes: 2 additions & 2 deletions crates/nu-command/tests/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn sets_the_column_from_a_block_full_stream_output() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
{content: null}
| update content { open --raw cargo_sample.toml | lines | first 5 }
| get content.1
| str contains "nu"
Expand All @@ -58,7 +58,7 @@ fn sets_the_column_from_a_subexpression() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
{content: null}
| update content (open --raw cargo_sample.toml | lines | first 5)
| get content.1
| str contains "nu"
Expand Down
4 changes: 2 additions & 2 deletions crates/nu-command/tests/commands/upsert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn sets_the_column_from_a_block_full_stream_output() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
{content: null}
| upsert content { open --raw cargo_sample.toml | lines | first 5 }
| get content.1
| str contains "nu"
Expand All @@ -58,7 +58,7 @@ fn sets_the_column_from_a_subexpression() {
let actual = nu!(
cwd: "tests/fixtures/formats", pipeline(
r#"
wrap content
{content: null}
| upsert content (open --raw cargo_sample.toml | lines | first 5)
| get content.1
| str contains "nu"
Expand Down
30 changes: 22 additions & 8 deletions crates/nu-engine/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,28 @@ pub fn eval_block(

match engine_state.find_decl("table".as_bytes(), &[]) {
Some(decl_id) => {
let table = engine_state.get_decl(decl_id).run(
engine_state,
stack,
&Call::new(Span::new(0, 0)),
input,
)?;

print_or_return(table, config)?;
let table = engine_state.get_decl(decl_id);

if let Some(block_id) = table.get_block_id() {
let block = engine_state.get_block(block_id);
eval_block(
engine_state,
stack,
block,
input,
redirect_stdout,
redirect_stderr,
)?;
} else {
let table = table.run(
engine_state,
stack,
&Call::new(Span::new(0, 0)),
input,
)?;

print_or_return(table, config)?;
}
}
None => {
print_or_return(input, config)?;
Expand Down
1 change: 1 addition & 0 deletions crates/nu-protocol/src/pipeline_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl PipelineData {

pub fn is_nothing(&self) -> bool {
matches!(self, PipelineData::Value(Value::Nothing { .. }, ..))
|| matches!(self, PipelineData::Empty)
}

/// PipelineData doesn't always have a Span, but we can try!
Expand Down