forked from extern/nushell
All tests pass
This commit is contained in:
parent
dd18122a24
commit
efd9631a90
@ -41,6 +41,33 @@ impl UnevaluatedCallInfo {
|
||||
name_span: self.name_span,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn has_it_or_block(&self) -> bool {
|
||||
use hir::RawExpression;
|
||||
use hir::Variable;
|
||||
|
||||
if let Some(positional) = &self.args.positional() {
|
||||
for pos in positional {
|
||||
match pos {
|
||||
Tagged {
|
||||
item: RawExpression::Variable(Variable::It(_)),
|
||||
..
|
||||
} => {
|
||||
return true;
|
||||
}
|
||||
Tagged {
|
||||
item: RawExpression::Block(_),
|
||||
..
|
||||
} => {
|
||||
return true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||
@ -465,29 +492,44 @@ impl Command {
|
||||
args: CommandArgs,
|
||||
registry: CommandRegistry,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
println!("raw_args: {:?}", args.call_info);
|
||||
let raw_args = RawCommandArgs {
|
||||
host: args.host,
|
||||
shell_manager: args.shell_manager,
|
||||
call_info: args.call_info,
|
||||
};
|
||||
|
||||
let out = args
|
||||
.input
|
||||
.values
|
||||
.map(move |x| {
|
||||
let call_info = raw_args
|
||||
.clone()
|
||||
.call_info
|
||||
.evaluate(®istry, &Scope::it_value(x.clone()))
|
||||
.unwrap();
|
||||
command
|
||||
.run(&call_info, ®istry, &raw_args.shell_manager, x)
|
||||
.unwrap()
|
||||
})
|
||||
.flatten();
|
||||
if raw_args.call_info.has_it_or_block() {
|
||||
let out = args
|
||||
.input
|
||||
.values
|
||||
.map(move |x| {
|
||||
let call_info = raw_args
|
||||
.clone()
|
||||
.call_info
|
||||
.evaluate(®istry, &Scope::it_value(x.clone()))
|
||||
.unwrap();
|
||||
match command.run(&call_info, ®istry, &raw_args.shell_manager, x) {
|
||||
Ok(o) => o,
|
||||
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]),
|
||||
}
|
||||
})
|
||||
.flatten();
|
||||
|
||||
Ok(out.to_output_stream())
|
||||
Ok(out.to_output_stream())
|
||||
} else {
|
||||
let nothing = Value::nothing().tagged(Tag::unknown());
|
||||
let call_info = raw_args
|
||||
.clone()
|
||||
.call_info
|
||||
.evaluate(®istry, &Scope::it_value(nothing.clone()))
|
||||
.unwrap();
|
||||
// We don't have an $it or block, so just execute what we have
|
||||
let out = match command.run(&call_info, ®istry, &raw_args.shell_manager, nothing) {
|
||||
Ok(o) => o,
|
||||
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]),
|
||||
};
|
||||
Ok(out.to_output_stream())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,6 @@ fn run(
|
||||
let cwd = PathBuf::from(shell_manager.path());
|
||||
let full_path = PathBuf::from(cwd);
|
||||
|
||||
println!("{:?}", call_info.args.nth(0));
|
||||
|
||||
let path = match call_info
|
||||
.args
|
||||
.nth(0)
|
||||
|
@ -290,7 +290,6 @@ crate fn evaluate_args(
|
||||
scope: &Scope,
|
||||
source: &Text,
|
||||
) -> Result<EvaluatedArgs, ShellError> {
|
||||
println!("positional (before): {:?}", call);
|
||||
let positional: Result<Option<Vec<_>>, _> = call
|
||||
.positional()
|
||||
.as_ref()
|
||||
@ -301,7 +300,6 @@ crate fn evaluate_args(
|
||||
})
|
||||
.transpose();
|
||||
|
||||
println!("positional: {:?}", positional);
|
||||
let positional = positional?;
|
||||
|
||||
let named: Result<Option<IndexMap<String, Tagged<Value>>>, ShellError> = call
|
||||
|
Loading…
Reference in New Issue
Block a user