forked from extern/nushell
Improve empty pipelines (#7383)
# Description This fix changes pipelines to allow them to actually be empty. Mapping over empty pipelines gives empty pipelines. Empty pipelines immediately return `None` when iterated. This removes a some of where `Span::new(0, 0)` was coming from, though there are other cases where we still use it. # User-Facing Changes None # 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:
@ -196,7 +196,7 @@ impl Command for Cd {
|
||||
match have_permission(&path_tointo) {
|
||||
PermissionResult::PermissionOk => {
|
||||
stack.add_env_var("PWD".into(), path_value);
|
||||
Ok(PipelineData::new(call.head))
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
PermissionResult::PermissionDenied(reason) => Err(ShellError::IOError(format!(
|
||||
"Cannot change directory to {}: {}",
|
||||
|
@ -2,8 +2,7 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, RawStream, ShellError, Signature, Span, Spanned, SyntaxShape,
|
||||
Value,
|
||||
Category, Example, PipelineData, RawStream, ShellError, Signature, Spanned, SyntaxShape, Value,
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::{BufWriter, Write};
|
||||
@ -160,7 +159,7 @@ impl Command for Save {
|
||||
file.flush()?
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
Value::Binary { val, .. } => {
|
||||
if let Err(err) = file.write_all(&val) {
|
||||
@ -169,7 +168,7 @@ impl Command for Save {
|
||||
file.flush()?
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
Value::List { vals, .. } => {
|
||||
let val = vals
|
||||
@ -185,7 +184,7 @@ impl Command for Save {
|
||||
file.flush()?
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
v => Err(ShellError::UnsupportedInput(
|
||||
format!("{:?} not supported", v.get_type()),
|
||||
@ -194,7 +193,7 @@ impl Command for Save {
|
||||
}
|
||||
} else {
|
||||
match input {
|
||||
PipelineData::ExternalStream { stdout: None, .. } => Ok(PipelineData::new(span)),
|
||||
PipelineData::ExternalStream { stdout: None, .. } => Ok(PipelineData::empty()),
|
||||
PipelineData::ExternalStream {
|
||||
stdout: Some(stream),
|
||||
stderr,
|
||||
@ -202,16 +201,16 @@ impl Command for Save {
|
||||
} => {
|
||||
// delegate a thread to redirect stderr to result.
|
||||
let handler = stderr.map(|stderr_stream| match stderr_file {
|
||||
Some(stderr_file) => std::thread::spawn(move || {
|
||||
stream_to_file(stderr_stream, stderr_file, span)
|
||||
}),
|
||||
Some(stderr_file) => {
|
||||
std::thread::spawn(move || stream_to_file(stderr_stream, stderr_file))
|
||||
}
|
||||
None => std::thread::spawn(move || {
|
||||
let _ = stderr_stream.into_bytes();
|
||||
Ok(PipelineData::new(span))
|
||||
Ok(PipelineData::empty())
|
||||
}),
|
||||
});
|
||||
|
||||
let res = stream_to_file(stream, file, span);
|
||||
let res = stream_to_file(stream, file);
|
||||
if let Some(h) = handler {
|
||||
match h.join() {
|
||||
Err(err) => {
|
||||
@ -236,7 +235,7 @@ impl Command for Save {
|
||||
file.flush()?
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
Value::Binary { val, .. } => {
|
||||
if let Err(err) = file.write_all(&val) {
|
||||
@ -245,7 +244,7 @@ impl Command for Save {
|
||||
file.flush()?
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
Value::List { vals, .. } => {
|
||||
let val = vals
|
||||
@ -261,7 +260,7 @@ impl Command for Save {
|
||||
file.flush()?
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(span))
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
v => Err(ShellError::UnsupportedInput(
|
||||
format!("{:?} not supported", v.get_type()),
|
||||
@ -303,11 +302,7 @@ impl Command for Save {
|
||||
}
|
||||
}
|
||||
|
||||
fn stream_to_file(
|
||||
mut stream: RawStream,
|
||||
file: File,
|
||||
span: Span,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
fn stream_to_file(mut stream: RawStream, file: File) -> Result<PipelineData, ShellError> {
|
||||
let mut writer = BufWriter::new(file);
|
||||
|
||||
stream
|
||||
@ -331,5 +326,5 @@ fn stream_to_file(
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.map(|_| PipelineData::new(span))
|
||||
.map(|_| PipelineData::empty())
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ impl Command for Touch {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(call.head))
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -271,7 +271,7 @@ impl Command for Watch {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(PipelineData::new(call.head))
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
Reference in New Issue
Block a user