This commit is contained in:
JT
2021-10-25 19:31:39 +13:00
parent 397a31e69c
commit b5965ee8ef
60 changed files with 502 additions and 455 deletions

View File

@ -1,6 +1,6 @@
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, Signature, SyntaxShape, Value};
#[derive(Clone)]
@ -21,11 +21,12 @@ impl Command for Cd {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let path: Option<String> = call.opt(context, 0)?;
let path: Option<String> = call.opt(engine_state, stack, 0)?;
let path = match path {
Some(path) => {
@ -41,7 +42,7 @@ impl Command for Cd {
//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
context.add_env_var("PWD".into(), path);
stack.add_env_var("PWD".into(), path);
Ok(PipelineData::new())
}
}

View File

@ -5,7 +5,7 @@ use super::util::get_interactive_confirmation;
use nu_engine::CallExt;
use nu_path::canonicalize_with;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape, Value};
use crate::filesystem::util::FileStructure;
@ -38,12 +38,13 @@ impl Command for Cp {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
let source: String = call.req(context, 0)?;
let destination: String = call.req(context, 1)?;
let source: String = call.req(engine_state, stack, 0)?;
let destination: String = call.req(engine_state, stack, 1)?;
let interactive = call.has_flag("interactive");
let force = call.has_flag("force");

View File

@ -1,7 +1,7 @@
use chrono::{DateTime, Utc};
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape, Value};
#[derive(Clone)]
@ -27,12 +27,13 @@ impl Command for Ls {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let pattern = if let Some(expr) = call.positional.get(0) {
let result = eval_expression(context, expr)?;
let result = eval_expression(engine_state, stack, expr)?;
let mut result = result.as_string()?;
let path = std::path::Path::new(&result);

View File

@ -3,7 +3,7 @@ use std::env::current_dir;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{
IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value, ValueStream,
};
@ -32,13 +32,14 @@ impl Command for Mkdir {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
let path = current_dir()?;
let mut directories = call
.rest::<String>(context, 0)?
.rest::<String>(engine_state, stack, 0)?
.into_iter()
.map(|dir| path.join(dir))
.peekable();

View File

@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
use super::util::get_interactive_confirmation;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape, Value};
#[derive(Clone)]
@ -38,13 +38,14 @@ impl Command for Mv {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
// TODO: handle invalid directory or insufficient permissions when moving
let source: String = call.req(context, 0)?;
let destination: String = call.req(context, 1)?;
let source: String = call.req(engine_state, stack, 0)?;
let destination: String = call.req(engine_state, stack, 1)?;
let interactive = call.has_flag("interactive");
let force = call.has_flag("force");

View File

@ -7,7 +7,7 @@ use super::util::get_interactive_confirmation;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{
IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value, ValueStream,
};
@ -59,15 +59,20 @@ impl Command for Rm {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
rm(context, call)
rm(engine_state, stack, call)
}
}
fn rm(context: &EvaluationContext, call: &Call) -> Result<PipelineData, ShellError> {
fn rm(
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
) -> Result<PipelineData, ShellError> {
let trash = call.has_flag("trash");
let permanent = call.has_flag("permanent");
let interactive = call.has_flag("interactive");
@ -98,7 +103,7 @@ fn rm(context: &EvaluationContext, call: &Call) -> Result<PipelineData, ShellErr
let current_path = current_dir()?;
let mut paths = call
.rest::<String>(context, 0)?
.rest::<String>(engine_state, stack, 0)?
.into_iter()
.map(|path| current_path.join(path))
.peekable();

View File

@ -2,7 +2,7 @@ use std::fs::OpenOptions;
use nu_engine::CallExt;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::engine::{Command, EngineState, EvaluationContext, Stack};
use nu_protocol::{PipelineData, ShellError, Signature, SyntaxShape, Value};
#[derive(Clone)]
@ -29,12 +29,13 @@ impl Command for Touch {
fn run(
&self,
context: &EvaluationContext,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
let target: String = call.req(context, 0)?;
let rest: Vec<String> = call.rest(context, 1)?;
let target: String = call.req(engine_state, stack, 0)?;
let rest: Vec<String> = call.rest(engine_state, stack, 1)?;
for (index, item) in vec![target].into_iter().chain(rest).enumerate() {
match OpenOptions::new().write(true).create(true).open(&item) {