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.
This commit is contained in:
JT 2023-03-04 11:31:01 +13:00 committed by GitHub
parent a7b5bd18ba
commit 6148314dcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<PipelineData, ShellError> {
let args: Vec<Value> = 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())