Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix internal $it paths #677

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 16 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
let mut input = ClassifiedInputStream::new();

let mut iter = pipeline.commands.into_iter().peekable();
let mut is_first_command = true;

loop {
let item: Option<ClassifiedCommand> = iter.next();
Expand All @@ -457,20 +458,29 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
(
Some(ClassifiedCommand::Internal(left)),
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),
Err(err) => return LineResult::Error(line.clone(), err),
},

(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),
Err(err) => return LineResult::Error(line.clone(), err),
}
}

(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),
Err(err) => return LineResult::Error(line.clone(), err),
}
Expand All @@ -497,7 +507,9 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
Err(err) => return LineResult::Error(line.clone(), err),
}
}
}
};

is_first_command = false;
}

LineResult::Success(line.clone())
Expand Down
6 changes: 3 additions & 3 deletions src/commands/autoview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn autoview(
{
let binary = context.get_command("binaryview");
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;
} else {
for i in input {
Expand All @@ -61,7 +61,7 @@ pub fn autoview(
} else if is_single_origined_text_value(&input) {
let text = context.get_command("textview");
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;
} else {
for i in input {
Expand All @@ -84,7 +84,7 @@ pub fn autoview(
}
} else {
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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/commands/classified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl InternalCommand {
context: &mut Context,
input: ClassifiedInputStream,
source: Text,
is_first_command: bool,
) -> Result<InputStream, ShellError> {
if log_enabled!(log::Level::Trace) {
trace!(target: "nu::run::internal", "->");
Expand All @@ -113,6 +114,7 @@ impl InternalCommand {
self.args,
&source,
objects,
is_first_command,
);

let result = trace_out_stream!(target: "nu::trace_stream::internal", source: &source, "output" = result);
Expand Down
42 changes: 11 additions & 31 deletions src/commands/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,6 @@ impl UnevaluatedCallInfo {
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)]
Expand Down Expand Up @@ -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 {
Command::WholeStream(command) => match command.run(args, registry) {
Ok(stream) => stream,
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)
}
}
}

Expand All @@ -571,14 +551,15 @@ impl Command {
command: Arc<dyn PerItemCommand>,
args: CommandArgs,
registry: CommandRegistry,
is_first_command: bool,
) -> OutputStream {
let raw_args = RawCommandArgs {
host: args.host,
shell_manager: args.shell_manager,
call_info: args.call_info,
};

if raw_args.call_info.has_it_or_block() {
if !is_first_command {
let out = args
.input
.values
Expand All @@ -603,7 +584,6 @@ impl Command {
.call_info
.evaluate(&registry, &Scope::it_value(nothing.clone()))
.unwrap();
// We don't have an $it or block, so just execute what we have

match command
.run(&call_info, &registry, &raw_args, nothing)
Expand Down
1 change: 1 addition & 0 deletions src/commands/enter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl PerItemCommand for Enter {
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;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn run(
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;
for res in result_vec {
match res {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn run(
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;
for res in result_vec {
match res {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn run(
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;
for res in result_vec {
match res {
Expand Down Expand Up @@ -195,6 +195,7 @@ pub async fn post(
let mut result = converter.run(
new_args.with_input(vec![item.clone().tagged(tag.clone())]),
&registry,
false,
);
let result_vec: Vec<Result<ReturnSuccess, ShellError>> =
result.drain_vec().await;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn save(
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;
if converter.is_binary() {
process_binary_return_success!(result_vec, name_tag)
Expand Down
3 changes: 2 additions & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ impl Context {
args: hir::Call,
source: &Text,
input: InputStream,
is_first_command: bool,
) -> OutputStream {
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(
Expand Down