mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 06:35:56 +02:00
Improve external output in subexprs (#294)
This commit is contained in:
@ -28,9 +28,9 @@ impl Command for Alias {
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Ok(PipelineData::new())
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ impl Command for Def {
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Ok(PipelineData::new())
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value, ValueStream,
|
||||
};
|
||||
use nu_protocol::{Example, PipelineData, ShellError, Signature, SyntaxShape, Value, ValueStream};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Echo;
|
||||
@ -43,7 +41,7 @@ impl Command for Echo {
|
||||
// When there are no elements, we echo the empty string
|
||||
std::cmp::Ordering::Less => PipelineData::Value(Value::String {
|
||||
val: "".to_string(),
|
||||
span: Span::unknown(),
|
||||
span: call.head,
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
@ -29,9 +29,9 @@ impl Command for ExportDef {
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Ok(PipelineData::new())
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ impl Command for For {
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
let head = call.head;
|
||||
let var_id = call.positional[0]
|
||||
.as_var()
|
||||
.expect("internal error: missing variable");
|
||||
@ -69,8 +70,8 @@ impl Command for For {
|
||||
stack.add_var(var_id, x);
|
||||
|
||||
//let block = engine_state.get_block(block_id);
|
||||
match eval_block(&engine_state, &mut stack, &block, PipelineData::new()) {
|
||||
Ok(pipeline_data) => pipeline_data.into_value(),
|
||||
match eval_block(&engine_state, &mut stack, &block, PipelineData::new(head)) {
|
||||
Ok(pipeline_data) => pipeline_data.into_value(head),
|
||||
Err(error) => Value::Error { error },
|
||||
}
|
||||
})
|
||||
@ -81,8 +82,8 @@ impl Command for For {
|
||||
stack.add_var(var_id, x);
|
||||
|
||||
//let block = engine_state.get_block(block_id);
|
||||
match eval_block(&engine_state, &mut stack, &block, PipelineData::new()) {
|
||||
Ok(pipeline_data) => pipeline_data.into_value(),
|
||||
match eval_block(&engine_state, &mut stack, &block, PipelineData::new(head)) {
|
||||
Ok(pipeline_data) => pipeline_data.into_value(head),
|
||||
Err(error) => Value::Error { error },
|
||||
}
|
||||
})
|
||||
@ -90,7 +91,7 @@ impl Command for For {
|
||||
x => {
|
||||
stack.add_var(var_id, x);
|
||||
|
||||
eval_block(&engine_state, &mut stack, &block, PipelineData::new())
|
||||
eval_block(&engine_state, &mut stack, &block, PipelineData::new(head))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ impl Command for Hide {
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Ok(PipelineData::new())
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
}
|
||||
|
@ -40,9 +40,9 @@ impl Command for If {
|
||||
let else_case = call.positional.get(2);
|
||||
|
||||
let result = eval_expression(engine_state, stack, cond)?;
|
||||
match result {
|
||||
match &result {
|
||||
Value::Bool { val, .. } => {
|
||||
if val {
|
||||
if *val {
|
||||
let block = engine_state.get_block(then_block);
|
||||
let mut stack = stack.collect_captures(&block.captures);
|
||||
eval_block(engine_state, &mut stack, block, input)
|
||||
@ -61,10 +61,14 @@ impl Command for If {
|
||||
.map(|x| x.into_pipeline_data())
|
||||
}
|
||||
} else {
|
||||
Ok(PipelineData::new())
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
}
|
||||
_ => Err(ShellError::CantConvert("bool".into(), result.span()?)),
|
||||
x => Err(ShellError::CantConvert(
|
||||
"bool".into(),
|
||||
x.get_type().to_string(),
|
||||
result.span()?,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,6 @@ impl Command for Let {
|
||||
//println!("Adding: {:?} to {}", rhs, var_id);
|
||||
|
||||
stack.add_var(var_id, rhs);
|
||||
Ok(PipelineData::new())
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ impl Command for Module {
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Ok(PipelineData::new())
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ impl Command for Register {
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Ok(PipelineData::new())
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ impl Command for Use {
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
_call: &Call,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Ok(PipelineData::new())
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user