mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
All tests pass
This commit is contained in:
parent
dd18122a24
commit
efd9631a90
3 changed files with 58 additions and 20 deletions
|
@ -41,6 +41,33 @@ impl UnevaluatedCallInfo {
|
||||||
name_span: self.name_span,
|
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)]
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||||
|
@ -465,29 +492,44 @@ impl Command {
|
||||||
args: CommandArgs,
|
args: CommandArgs,
|
||||||
registry: CommandRegistry,
|
registry: CommandRegistry,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
println!("raw_args: {:?}", args.call_info);
|
|
||||||
let raw_args = RawCommandArgs {
|
let raw_args = RawCommandArgs {
|
||||||
host: args.host,
|
host: args.host,
|
||||||
shell_manager: args.shell_manager,
|
shell_manager: args.shell_manager,
|
||||||
call_info: args.call_info,
|
call_info: args.call_info,
|
||||||
};
|
};
|
||||||
|
|
||||||
let out = args
|
if raw_args.call_info.has_it_or_block() {
|
||||||
.input
|
let out = args
|
||||||
.values
|
.input
|
||||||
.map(move |x| {
|
.values
|
||||||
let call_info = raw_args
|
.map(move |x| {
|
||||||
.clone()
|
let call_info = raw_args
|
||||||
.call_info
|
.clone()
|
||||||
.evaluate(®istry, &Scope::it_value(x.clone()))
|
.call_info
|
||||||
.unwrap();
|
.evaluate(®istry, &Scope::it_value(x.clone()))
|
||||||
command
|
.unwrap();
|
||||||
.run(&call_info, ®istry, &raw_args.shell_manager, x)
|
match command.run(&call_info, ®istry, &raw_args.shell_manager, x) {
|
||||||
.unwrap()
|
Ok(o) => o,
|
||||||
})
|
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]),
|
||||||
.flatten();
|
}
|
||||||
|
})
|
||||||
|
.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 cwd = PathBuf::from(shell_manager.path());
|
||||||
let full_path = PathBuf::from(cwd);
|
let full_path = PathBuf::from(cwd);
|
||||||
|
|
||||||
println!("{:?}", call_info.args.nth(0));
|
|
||||||
|
|
||||||
let path = match call_info
|
let path = match call_info
|
||||||
.args
|
.args
|
||||||
.nth(0)
|
.nth(0)
|
||||||
|
|
|
@ -290,7 +290,6 @@ crate fn evaluate_args(
|
||||||
scope: &Scope,
|
scope: &Scope,
|
||||||
source: &Text,
|
source: &Text,
|
||||||
) -> Result<EvaluatedArgs, ShellError> {
|
) -> Result<EvaluatedArgs, ShellError> {
|
||||||
println!("positional (before): {:?}", call);
|
|
||||||
let positional: Result<Option<Vec<_>>, _> = call
|
let positional: Result<Option<Vec<_>>, _> = call
|
||||||
.positional()
|
.positional()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -301,7 +300,6 @@ crate fn evaluate_args(
|
||||||
})
|
})
|
||||||
.transpose();
|
.transpose();
|
||||||
|
|
||||||
println!("positional: {:?}", positional);
|
|
||||||
let positional = positional?;
|
let positional = positional?;
|
||||||
|
|
||||||
let named: Result<Option<IndexMap<String, Tagged<Value>>>, ShellError> = call
|
let named: Result<Option<IndexMap<String, Tagged<Value>>>, ShellError> = call
|
||||||
|
|
Loading…
Reference in a new issue