mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 06:38:44 +02:00
Require let to be a statement (#594)
This commit is contained in:
31
src/main.rs
31
src/main.rs
@ -21,6 +21,7 @@ use reedline::{
|
||||
};
|
||||
use std::{
|
||||
io::Write,
|
||||
path::Path,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
@ -402,7 +403,35 @@ fn main() -> Result<()> {
|
||||
|
||||
let input = line_editor.read_line(prompt);
|
||||
match input {
|
||||
Ok(Signal::Success(s)) => {
|
||||
Ok(Signal::Success(mut s)) => {
|
||||
// Check if this is a single call to a directory, if so auto-cd
|
||||
let path = nu_path::expand_path(&s);
|
||||
let orig = s.clone();
|
||||
s = path.to_string_lossy().to_string();
|
||||
|
||||
let path = Path::new(&s);
|
||||
if (orig.starts_with('.')
|
||||
|| orig.starts_with('~')
|
||||
|| orig.starts_with('/')
|
||||
|| orig.starts_with('\\'))
|
||||
&& path.is_dir()
|
||||
{
|
||||
// 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: s.clone(),
|
||||
span: Span { start: 0, end: 0 },
|
||||
},
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
eval_source(
|
||||
&mut engine_state,
|
||||
&mut stack,
|
||||
|
@ -113,3 +113,8 @@ fn long_flag() -> TestResult {
|
||||
"100",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn let_not_statement() -> TestResult {
|
||||
fail_test(r#"let x = "hello" | str length"#, "can't")
|
||||
}
|
||||
|
Reference in New Issue
Block a user