mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:14:44 +02:00
Rename IoStream
to OutDest
(#12433)
# Description I spent a while trying to come up with a good name for what is currently `IoStream`. Looking back, this name is not the best, because it: 1. Implies that it is a stream, when it all it really does is specify the output destination for a stream/pipeline. 2. Implies that it handles input and output, when it really only handles output. So, this PR renames `IoStream` to `OutDest` instead, which should be more clear.
This commit is contained in:
@ -69,7 +69,7 @@ impl CallExt for Call {
|
||||
if flag_name == name.0.item {
|
||||
return if let Some(expr) = &name.2 {
|
||||
// Check --flag=false
|
||||
let stack = &mut stack.use_call_arg_stdio();
|
||||
let stack = &mut stack.use_call_arg_out_dest();
|
||||
let result = eval_expression::<WithoutDebug>(engine_state, stack, expr)?;
|
||||
match result {
|
||||
Value::Bool { val, .. } => Ok(val),
|
||||
@ -96,7 +96,7 @@ impl CallExt for Call {
|
||||
name: &str,
|
||||
) -> Result<Option<T>, ShellError> {
|
||||
if let Some(expr) = self.get_flag_expr(name) {
|
||||
let stack = &mut stack.use_call_arg_stdio();
|
||||
let stack = &mut stack.use_call_arg_out_dest();
|
||||
let result = eval_expression::<WithoutDebug>(engine_state, stack, expr)?;
|
||||
FromValue::from_value(result).map(Some)
|
||||
} else {
|
||||
@ -110,7 +110,7 @@ impl CallExt for Call {
|
||||
stack: &mut Stack,
|
||||
starting_pos: usize,
|
||||
) -> Result<Vec<T>, ShellError> {
|
||||
let stack = &mut stack.use_call_arg_stdio();
|
||||
let stack = &mut stack.use_call_arg_out_dest();
|
||||
let mut output = vec![];
|
||||
|
||||
for result in self.rest_iter_flattened(starting_pos, |expr| {
|
||||
@ -129,7 +129,7 @@ impl CallExt for Call {
|
||||
pos: usize,
|
||||
) -> Result<Option<T>, ShellError> {
|
||||
if let Some(expr) = self.positional_nth(pos) {
|
||||
let stack = &mut stack.use_call_arg_stdio();
|
||||
let stack = &mut stack.use_call_arg_out_dest();
|
||||
let result = eval_expression::<WithoutDebug>(engine_state, stack, expr)?;
|
||||
FromValue::from_value(result).map(Some)
|
||||
} else {
|
||||
@ -157,7 +157,7 @@ impl CallExt for Call {
|
||||
pos: usize,
|
||||
) -> Result<T, ShellError> {
|
||||
if let Some(expr) = self.positional_nth(pos) {
|
||||
let stack = &mut stack.use_call_arg_stdio();
|
||||
let stack = &mut stack.use_call_arg_out_dest();
|
||||
let result = eval_expression::<WithoutDebug>(engine_state, stack, expr)?;
|
||||
FromValue::from_value(result)
|
||||
} else if self.positional_len() == 0 {
|
||||
@ -177,7 +177,7 @@ impl CallExt for Call {
|
||||
name: &str,
|
||||
) -> Result<T, ShellError> {
|
||||
if let Some(expr) = self.get_parser_info(name) {
|
||||
let stack = &mut stack.use_call_arg_stdio();
|
||||
let stack = &mut stack.use_call_arg_out_dest();
|
||||
let result = eval_expression::<WithoutDebug>(engine_state, stack, expr)?;
|
||||
FromValue::from_value(result)
|
||||
} else if self.parser_info.is_empty() {
|
||||
|
@ -8,7 +8,7 @@ use nu_protocol::{
|
||||
debugger::DebugContext,
|
||||
engine::{Closure, EngineState, Redirection, Stack},
|
||||
eval_base::Eval,
|
||||
Config, FromValue, IntoPipelineData, IoStream, PipelineData, ShellError, Span, Spanned, Type,
|
||||
Config, FromValue, IntoPipelineData, OutDest, PipelineData, ShellError, Span, Spanned, Type,
|
||||
Value, VarId, ENV_VARIABLE_ID,
|
||||
};
|
||||
use std::{borrow::Cow, fs::OpenOptions, path::PathBuf};
|
||||
@ -302,8 +302,8 @@ pub fn eval_expression_with_input<D: DebugContext>(
|
||||
// If input is PipelineData::ExternalStream,
|
||||
// then `might_consume_external_result` will consume `stderr` if `stdout` is `None`.
|
||||
// This should not happen if the user wants to capture stderr.
|
||||
if !matches!(stack.stdout(), IoStream::Pipe | IoStream::Capture)
|
||||
&& matches!(stack.stderr(), IoStream::Capture)
|
||||
if !matches!(stack.stdout(), OutDest::Pipe | OutDest::Capture)
|
||||
&& matches!(stack.stderr(), OutDest::Capture)
|
||||
{
|
||||
Ok((input, false))
|
||||
} else {
|
||||
@ -320,7 +320,7 @@ fn eval_redirection<D: DebugContext>(
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
target: &RedirectionTarget,
|
||||
next_out: Option<IoStream>,
|
||||
next_out: Option<OutDest>,
|
||||
) -> Result<Redirection, ShellError> {
|
||||
match target {
|
||||
RedirectionTarget::File { expr, append, .. } => {
|
||||
@ -337,7 +337,7 @@ fn eval_redirection<D: DebugContext>(
|
||||
}
|
||||
Ok(Redirection::file(options.create(true).open(path)?))
|
||||
}
|
||||
RedirectionTarget::Pipe { .. } => Ok(Redirection::Pipe(next_out.unwrap_or(IoStream::Pipe))),
|
||||
RedirectionTarget::Pipe { .. } => Ok(Redirection::Pipe(next_out.unwrap_or(OutDest::Pipe))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -345,7 +345,7 @@ fn eval_element_redirection<D: DebugContext>(
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
element_redirection: Option<&PipelineRedirection>,
|
||||
pipe_redirection: (Option<IoStream>, Option<IoStream>),
|
||||
pipe_redirection: (Option<OutDest>, Option<OutDest>),
|
||||
) -> Result<(Option<Redirection>, Option<Redirection>), ShellError> {
|
||||
let (next_out, next_err) = pipe_redirection;
|
||||
|
||||
@ -363,7 +363,7 @@ fn eval_element_redirection<D: DebugContext>(
|
||||
target,
|
||||
} => {
|
||||
let stderr = eval_redirection::<D>(engine_state, stack, target, None)?;
|
||||
if matches!(stderr, Redirection::Pipe(IoStream::Pipe)) {
|
||||
if matches!(stderr, Redirection::Pipe(OutDest::Pipe)) {
|
||||
// e>| redirection, don't override current stack `stdout`
|
||||
Ok((
|
||||
None,
|
||||
@ -438,10 +438,10 @@ fn eval_element_with_input_inner<D: DebugContext>(
|
||||
}
|
||||
}
|
||||
|
||||
let data = if matches!(stack.pipe_stdout(), Some(IoStream::File(_)))
|
||||
&& !matches!(stack.pipe_stderr(), Some(IoStream::Pipe))
|
||||
let data = if matches!(stack.pipe_stdout(), Some(OutDest::File(_)))
|
||||
&& !matches!(stack.pipe_stderr(), Some(OutDest::Pipe))
|
||||
{
|
||||
data.write_to_io_streams(engine_state, stack)?
|
||||
data.write_to_out_dests(engine_state, stack)?
|
||||
} else {
|
||||
data
|
||||
};
|
||||
@ -496,12 +496,12 @@ pub fn eval_block<D: DebugContext>(
|
||||
|
||||
for (i, element) in elements.iter().enumerate() {
|
||||
let next = elements.get(i + 1).unwrap_or(last);
|
||||
let (next_out, next_err) = next.stdio_redirect(engine_state);
|
||||
let (next_out, next_err) = next.pipe_redirection(engine_state);
|
||||
let (stdout, stderr) = eval_element_redirection::<D>(
|
||||
engine_state,
|
||||
stack,
|
||||
element.redirection.as_ref(),
|
||||
(next_out.or(Some(IoStream::Pipe)), next_err),
|
||||
(next_out.or(Some(OutDest::Pipe)), next_err),
|
||||
)?;
|
||||
let stack = &mut stack.push_redirection(stdout, stderr);
|
||||
let (output, failed) =
|
||||
|
Reference in New Issue
Block a user