Fix internal paths

This commit is contained in:
Jonathan Turner 2019-09-17 14:09:15 +12:00
parent 60dbca8bc6
commit 7fbd6ce232
11 changed files with 44 additions and 47 deletions

8
Cargo.lock generated
View File

@ -1556,7 +1556,7 @@ dependencies = [
"rawkey 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rawkey 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"roxmltree 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "roxmltree 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rusqlite 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", "rusqlite 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustyline 5.0.2 (git+https://github.com/kkawakam/rustyline)", "rustyline 5.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.100 (registry+https://github.com/rust-lang/crates.io-index)",
"serde-hjson 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde-hjson 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2195,8 +2195,8 @@ dependencies = [
[[package]] [[package]]
name = "rustyline" name = "rustyline"
version = "5.0.2" version = "5.0.3"
source = "git+https://github.com/kkawakam/rustyline#5e68e972810133a7343b75db30addc98aea63ba0" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.60 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3216,7 +3216,7 @@ dependencies = [
"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af"
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
"checksum rustyline 5.0.2 (git+https://github.com/kkawakam/rustyline)" = "<none>" "checksum rustyline 5.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4795e277e6e57dec9df62b515cd4991371daa80e8dc8d80d596e58722b89c417"
"checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997" "checksum ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
"checksum safemem 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e133ccc4f4d1cd4f89cc8a7ff618287d56dc7f638b8e38fc32c5fdcadc339dd5" "checksum safemem 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e133ccc4f4d1cd4f89cc8a7ff618287d56dc7f638b8e38fc32c5fdcadc339dd5"
"checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421"

View File

@ -432,6 +432,7 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
let mut input = ClassifiedInputStream::new(); let mut input = ClassifiedInputStream::new();
let mut iter = pipeline.commands.into_iter().peekable(); let mut iter = pipeline.commands.into_iter().peekable();
let mut is_first_command = true;
loop { loop {
let item: Option<ClassifiedCommand> = iter.next(); let item: Option<ClassifiedCommand> = iter.next();
@ -457,20 +458,29 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
( (
Some(ClassifiedCommand::Internal(left)), Some(ClassifiedCommand::Internal(left)),
Some(ClassifiedCommand::External(_)), Some(ClassifiedCommand::External(_)),
) => match left.run(ctx, input, Text::from(line)).await { ) => match left
.run(ctx, input, Text::from(line), is_first_command)
.await
{
Ok(val) => ClassifiedInputStream::from_input_stream(val), Ok(val) => ClassifiedInputStream::from_input_stream(val),
Err(err) => return LineResult::Error(line.clone(), err), Err(err) => return LineResult::Error(line.clone(), err),
}, },
(Some(ClassifiedCommand::Internal(left)), Some(_)) => { (Some(ClassifiedCommand::Internal(left)), Some(_)) => {
match left.run(ctx, input, Text::from(line)).await { match left
.run(ctx, input, Text::from(line), is_first_command)
.await
{
Ok(val) => ClassifiedInputStream::from_input_stream(val), Ok(val) => ClassifiedInputStream::from_input_stream(val),
Err(err) => return LineResult::Error(line.clone(), err), Err(err) => return LineResult::Error(line.clone(), err),
} }
} }
(Some(ClassifiedCommand::Internal(left)), None) => { (Some(ClassifiedCommand::Internal(left)), None) => {
match left.run(ctx, input, Text::from(line)).await { match left
.run(ctx, input, Text::from(line), is_first_command)
.await
{
Ok(val) => ClassifiedInputStream::from_input_stream(val), Ok(val) => ClassifiedInputStream::from_input_stream(val),
Err(err) => return LineResult::Error(line.clone(), err), Err(err) => return LineResult::Error(line.clone(), err),
} }
@ -497,7 +507,9 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
Err(err) => return LineResult::Error(line.clone(), err), Err(err) => return LineResult::Error(line.clone(), err),
} }
} }
} };
is_first_command = false;
} }
LineResult::Success(line.clone()) LineResult::Success(line.clone())

View File

@ -45,7 +45,7 @@ pub fn autoview(
{ {
let binary = context.get_command("binaryview"); let binary = context.get_command("binaryview");
if let Some(binary) = binary { if let Some(binary) = binary {
let result = binary.run(raw.with_input(input), &context.commands); let result = binary.run(raw.with_input(input), &context.commands, false);
result.collect::<Vec<_>>().await; result.collect::<Vec<_>>().await;
} else { } else {
for i in input { for i in input {
@ -61,7 +61,7 @@ pub fn autoview(
} else if is_single_origined_text_value(&input) { } else if is_single_origined_text_value(&input) {
let text = context.get_command("textview"); let text = context.get_command("textview");
if let Some(text) = text { if let Some(text) = text {
let result = text.run(raw.with_input(input), &context.commands); let result = text.run(raw.with_input(input), &context.commands, false);
result.collect::<Vec<_>>().await; result.collect::<Vec<_>>().await;
} else { } else {
for i in input { for i in input {
@ -84,7 +84,7 @@ pub fn autoview(
} }
} else { } else {
let table = context.expect_command("table"); let table = context.expect_command("table");
let result = table.run(raw.with_input(input), &context.commands); let result = table.run(raw.with_input(input), &context.commands, false);
result.collect::<Vec<_>>().await; result.collect::<Vec<_>>().await;
} }
} }

View File

@ -96,6 +96,7 @@ impl InternalCommand {
context: &mut Context, context: &mut Context,
input: ClassifiedInputStream, input: ClassifiedInputStream,
source: Text, source: Text,
is_first_command: bool,
) -> Result<InputStream, ShellError> { ) -> Result<InputStream, ShellError> {
if log_enabled!(log::Level::Trace) { if log_enabled!(log::Level::Trace) {
trace!(target: "nu::run::internal", "->"); trace!(target: "nu::run::internal", "->");
@ -113,6 +114,7 @@ impl InternalCommand {
self.args, self.args,
&source, &source,
objects, objects,
is_first_command,
); );
let result = trace_out_stream!(target: "nu::trace_stream::internal", source: &source, "output" = result); let result = trace_out_stream!(target: "nu::trace_stream::internal", source: &source, "output" = result);

View File

@ -41,33 +41,6 @@ impl UnevaluatedCallInfo {
name_tag: self.name_tag, name_tag: self.name_tag,
}) })
} }
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)]
@ -556,13 +529,20 @@ impl Command {
} }
} }
pub fn run(&self, args: CommandArgs, registry: &registry::CommandRegistry) -> OutputStream { pub fn run(
&self,
args: CommandArgs,
registry: &registry::CommandRegistry,
is_first_command: bool,
) -> OutputStream {
match self { match self {
Command::WholeStream(command) => match command.run(args, registry) { Command::WholeStream(command) => match command.run(args, registry) {
Ok(stream) => stream, Ok(stream) => stream,
Err(err) => OutputStream::one(Err(err)), Err(err) => OutputStream::one(Err(err)),
}, },
Command::PerItem(command) => self.run_helper(command.clone(), args, registry.clone()), Command::PerItem(command) => {
self.run_helper(command.clone(), args, registry.clone(), is_first_command)
}
} }
} }
@ -571,6 +551,7 @@ impl Command {
command: Arc<dyn PerItemCommand>, command: Arc<dyn PerItemCommand>,
args: CommandArgs, args: CommandArgs,
registry: CommandRegistry, registry: CommandRegistry,
is_first_command: bool,
) -> OutputStream { ) -> OutputStream {
let raw_args = RawCommandArgs { let raw_args = RawCommandArgs {
host: args.host, host: args.host,
@ -578,7 +559,7 @@ impl Command {
call_info: args.call_info, call_info: args.call_info,
}; };
if raw_args.call_info.has_it_or_block() { if !is_first_command {
let out = args let out = args
.input .input
.values .values
@ -603,7 +584,6 @@ impl Command {
.call_info .call_info
.evaluate(&registry, &Scope::it_value(nothing.clone())) .evaluate(&registry, &Scope::it_value(nothing.clone()))
.unwrap(); .unwrap();
// We don't have an $it or block, so just execute what we have
match command match command
.run(&call_info, &registry, &raw_args, nothing) .run(&call_info, &registry, &raw_args, nothing)

View File

@ -109,6 +109,7 @@ impl PerItemCommand for Enter {
let mut result = converter.run( let mut result = converter.run(
new_args.with_input(vec![tagged_contents]), new_args.with_input(vec![tagged_contents]),
&registry, &registry,
false
); );
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = let result_vec: Vec<Result<ReturnSuccess, ShellError>> =
result.drain_vec().await; result.drain_vec().await;

View File

@ -101,7 +101,7 @@ fn run(
name_tag: raw_args.call_info.name_tag, name_tag: raw_args.call_info.name_tag,
} }
}; };
let mut result = converter.run(new_args.with_input(vec![tagged_contents]), &registry); let mut result = converter.run(new_args.with_input(vec![tagged_contents]), &registry, false);
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await; let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
for res in result_vec { for res in result_vec {
match res { match res {

View File

@ -102,7 +102,7 @@ fn run(
name_tag: raw_args.call_info.name_tag, name_tag: raw_args.call_info.name_tag,
} }
}; };
let mut result = converter.run(new_args.with_input(vec![tagged_contents]), &registry); let mut result = converter.run(new_args.with_input(vec![tagged_contents]), &registry, false);
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await; let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
for res in result_vec { for res in result_vec {
match res { match res {

View File

@ -112,7 +112,7 @@ fn run(
name_tag: raw_args.call_info.name_tag, name_tag: raw_args.call_info.name_tag,
} }
}; };
let mut result = converter.run(new_args.with_input(vec![tagged_contents]), &registry); let mut result = converter.run(new_args.with_input(vec![tagged_contents]), &registry, false);
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await; let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
for res in result_vec { for res in result_vec {
match res { match res {
@ -195,6 +195,7 @@ pub async fn post(
let mut result = converter.run( let mut result = converter.run(
new_args.with_input(vec![item.clone().tagged(tag.clone())]), new_args.with_input(vec![item.clone().tagged(tag.clone())]),
&registry, &registry,
false,
); );
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = let result_vec: Vec<Result<ReturnSuccess, ShellError>> =
result.drain_vec().await; result.drain_vec().await;

View File

@ -188,7 +188,7 @@ fn save(
name_tag: raw_args.call_info.name_tag, name_tag: raw_args.call_info.name_tag,
} }
}; };
let mut result = converter.run(new_args.with_input(input), &registry); let mut result = converter.run(new_args.with_input(input), &registry, false);
let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await; let result_vec: Vec<Result<ReturnSuccess, ShellError>> = result.drain_vec().await;
if converter.is_binary() { if converter.is_binary() {
process_binary_return_success!(result_vec, name_tag) process_binary_return_success!(result_vec, name_tag)

View File

@ -125,9 +125,10 @@ impl Context {
args: hir::Call, args: hir::Call,
source: &Text, source: &Text,
input: InputStream, input: InputStream,
is_first_command: bool,
) -> OutputStream { ) -> OutputStream {
let command_args = self.command_args(args, input, source, source_map, name_tag); let command_args = self.command_args(args, input, source, source_map, name_tag);
command.run(command_args, self.registry()) command.run(command_args, self.registry(), is_first_command)
} }
fn call_info( fn call_info(