Require let to be a statement (#594)

This commit is contained in:
JT
2021-12-27 14:04:22 +11:00
committed by GitHub
parent de30236f38
commit 3706bef0a1
6 changed files with 58 additions and 31 deletions

View File

@ -1,7 +1,6 @@
use std::collections::HashMap;
use std::env;
use std::io::{BufRead, BufReader, Write};
use std::path::Path;
use std::process::{Command as CommandSys, Stdio};
use std::sync::atomic::Ordering;
use std::sync::mpsc;
@ -48,7 +47,7 @@ impl Command for External {
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let mut name: Spanned<String> = call.req(engine_state, stack, 0)?;
let name: Spanned<String> = call.req(engine_state, stack, 0)?;
let args: Vec<Value> = call.rest(engine_state, stack, 1)?;
let last_expression = call.has_flag("last_expression");
@ -56,34 +55,6 @@ impl Command for External {
let config = stack.get_config().unwrap_or_default();
let env_vars_str = env_to_strings(engine_state, stack, &config)?;
// Check if this is a single call to a directory, if so auto-cd
let path = nu_path::expand_path(&name.item);
let orig = name.item.clone();
name.item = path.to_string_lossy().to_string();
let path = Path::new(&name.item);
if (orig.starts_with('.')
|| orig.starts_with('~')
|| orig.starts_with('/')
|| orig.starts_with('\\'))
&& path.is_dir()
&& args.is_empty()
{
// We have an auto-cd
let _ = std::env::set_current_dir(&path);
//FIXME: this only changes the current scope, but instead this environment variable
//should probably be a block that loads the information from the state in the overlay
stack.add_env_var(
"PWD".into(),
Value::String {
val: name.item.clone(),
span: call.head,
},
);
return Ok(PipelineData::new(call.head));
}
let mut args_strs = vec![];
for arg in args {