From 6148314dcdd5cea4fd8f17492a664cb194c2f8fe Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Sat, 4 Mar 2023 11:31:01 +1300 Subject: [PATCH] print pipeline contents in `print` (#8305) # Description Have `print` print it's input, so it's easier to print a pipeline (esp after we land #8292 and related) # User-Facing Changes `print` will now print its input, if there are no args given # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --- crates/nu-cli/src/print.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/nu-cli/src/print.rs b/crates/nu-cli/src/print.rs index 563b2239f..1a6d7d146 100644 --- a/crates/nu-cli/src/print.rs +++ b/crates/nu-cli/src/print.rs @@ -47,15 +47,20 @@ Since this command has no output, there is no point in piping it with other comm engine_state: &EngineState, stack: &mut Stack, call: &Call, - _input: PipelineData, + input: PipelineData, ) -> Result { let args: Vec = call.rest(engine_state, stack, 0)?; let no_newline = call.has_flag("no-newline"); let to_stderr = call.has_flag("stderr"); - for arg in args { - arg.into_pipeline_data() - .print(engine_state, stack, no_newline, to_stderr)?; + // This will allow for easy printing of pipelines as well + if !args.is_empty() { + for arg in args { + arg.into_pipeline_data() + .print(engine_state, stack, no_newline, to_stderr)?; + } + } else if !input.is_nothing() { + input.print(engine_state, stack, no_newline, to_stderr)?; } Ok(PipelineData::empty())