forked from extern/nushell
Finish adding support for protecting value shells
This commit is contained in:
parent
78ca297e47
commit
303d27d4b6
@ -35,8 +35,6 @@ fn mkdir(
|
||||
args: MkdirArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
println!("shell clone");
|
||||
let shell_manager = context.shell_manager.clone();
|
||||
println!("mkdir");
|
||||
shell_manager.mkdir(args, context)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::commands::command::{EvaluatedWholeStreamCommandArgs, RunnablePerItemContext};
|
||||
use crate::commands::command::EvaluatedWholeStreamCommandArgs;
|
||||
use crate::commands::cp::CopyArgs;
|
||||
use crate::commands::mkdir::MkdirArgs;
|
||||
use crate::commands::mv::MoveArgs;
|
||||
@ -200,12 +200,13 @@ impl Shell for FilesystemShell {
|
||||
dst,
|
||||
recursive,
|
||||
}: CopyArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let name_span = context.name;
|
||||
let name_span = name;
|
||||
|
||||
let mut source = PathBuf::from(context.shell_manager.path());
|
||||
let mut destination = PathBuf::from(context.shell_manager.path());
|
||||
let mut source = PathBuf::from(path);
|
||||
let mut destination = PathBuf::from(path);
|
||||
|
||||
source.push(&src.item);
|
||||
destination.push(&dst.item);
|
||||
@ -476,15 +477,16 @@ impl Shell for FilesystemShell {
|
||||
|
||||
fn mkdir(
|
||||
&self,
|
||||
mkdir_args: MkdirArgs,
|
||||
RunnablePerItemContext {
|
||||
name,
|
||||
shell_manager,
|
||||
..
|
||||
}: &RunnablePerItemContext,
|
||||
MkdirArgs { rest: directories }: MkdirArgs,
|
||||
// RunnablePerItemContext {
|
||||
// name,
|
||||
// shell_manager,
|
||||
// ..
|
||||
// }: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
println!("full path");
|
||||
let full_path = PathBuf::from(shell_manager.path());
|
||||
let full_path = PathBuf::from(path);
|
||||
|
||||
if directories.len() == 0 {
|
||||
return Err(ShellError::labeled_error(
|
||||
@ -494,17 +496,13 @@ impl Shell for FilesystemShell {
|
||||
));
|
||||
}
|
||||
|
||||
println!("dirs");
|
||||
for dir in directories.iter() {
|
||||
println!("create at:");
|
||||
let create_at = {
|
||||
let mut loc = full_path.clone();
|
||||
loc.push(&dir.item);
|
||||
loc
|
||||
};
|
||||
|
||||
println!("{:?}", create_at);
|
||||
|
||||
match std::fs::create_dir_all(create_at) {
|
||||
Err(reason) => {
|
||||
return Err(ShellError::labeled_error(
|
||||
@ -513,27 +511,23 @@ impl Shell for FilesystemShell {
|
||||
dir.span(),
|
||||
))
|
||||
}
|
||||
Ok(_) => {
|
||||
println!("OK");
|
||||
}
|
||||
Ok(_) => {}
|
||||
}
|
||||
println!("End loop");
|
||||
}
|
||||
|
||||
println!("Done");
|
||||
|
||||
Ok(VecDeque::new())
|
||||
}
|
||||
|
||||
fn mv(
|
||||
&self,
|
||||
MoveArgs { src, dst }: MoveArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let name_span = context.name;
|
||||
let name_span = name;
|
||||
|
||||
let mut source = PathBuf::from(context.shell_manager.path());
|
||||
let mut destination = PathBuf::from(context.shell_manager.path());
|
||||
let mut source = PathBuf::from(path);
|
||||
let mut destination = PathBuf::from(path);
|
||||
|
||||
source.push(&src.item);
|
||||
destination.push(&dst.item);
|
||||
@ -832,11 +826,12 @@ impl Shell for FilesystemShell {
|
||||
fn rm(
|
||||
&self,
|
||||
RemoveArgs { target, recursive }: RemoveArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let name_span = context.name;
|
||||
let name_span = name;
|
||||
|
||||
let mut path = PathBuf::from(context.shell_manager.path());
|
||||
let mut path = PathBuf::from(path);
|
||||
|
||||
path.push(&target.item);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::commands::command::{EvaluatedWholeStreamCommandArgs, RunnablePerItemContext};
|
||||
use crate::commands::command::EvaluatedWholeStreamCommandArgs;
|
||||
use crate::commands::cp::CopyArgs;
|
||||
use crate::commands::mkdir::MkdirArgs;
|
||||
use crate::commands::mv::MoveArgs;
|
||||
@ -15,22 +15,26 @@ pub trait Shell: std::fmt::Debug {
|
||||
fn cp(
|
||||
&self,
|
||||
args: CopyArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError>;
|
||||
fn mkdir(
|
||||
&self,
|
||||
args: MkdirArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError>;
|
||||
fn mv(
|
||||
&self,
|
||||
args: MoveArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError>;
|
||||
fn rm(
|
||||
&self,
|
||||
args: RemoveArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError>;
|
||||
fn path(&self) -> String;
|
||||
fn set_path(&mut self, path: String);
|
||||
|
@ -117,9 +117,19 @@ impl ShellManager {
|
||||
args: CopyArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let env = self.shells.lock().unwrap();
|
||||
let env = self.shells.lock();
|
||||
|
||||
env[self.current_shell].cp(args, context)
|
||||
match env {
|
||||
Ok(x) => {
|
||||
let path = x[self.current_shell].path();
|
||||
x[self.current_shell].cp(args, context.name, &path)
|
||||
}
|
||||
Err(e) => Err(ShellError::labeled_error(
|
||||
format!("Internal error: could not lock {}", e),
|
||||
"Internal error: could not lock",
|
||||
context.name,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rm(
|
||||
@ -127,9 +137,19 @@ impl ShellManager {
|
||||
args: RemoveArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let env = self.shells.lock().unwrap();
|
||||
let env = self.shells.lock();
|
||||
|
||||
env[self.current_shell].rm(args, context)
|
||||
match env {
|
||||
Ok(x) => {
|
||||
let path = x[self.current_shell].path();
|
||||
x[self.current_shell].rm(args, context.name, &path)
|
||||
}
|
||||
Err(e) => Err(ShellError::labeled_error(
|
||||
format!("Internal error: could not lock {}", e),
|
||||
"Internal error: could not lock",
|
||||
context.name,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mkdir(
|
||||
@ -137,9 +157,19 @@ impl ShellManager {
|
||||
args: MkdirArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let env = self.shells.lock().unwrap();
|
||||
let env = self.shells.lock();
|
||||
|
||||
env[self.current_shell].mkdir(args, context)
|
||||
match env {
|
||||
Ok(x) => {
|
||||
let path = x[self.current_shell].path();
|
||||
x[self.current_shell].mkdir(args, context.name, &path)
|
||||
}
|
||||
Err(e) => Err(ShellError::labeled_error(
|
||||
format!("Internal error: could not lock {}", e),
|
||||
"Internal error: could not lock",
|
||||
context.name,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mv(
|
||||
@ -147,8 +177,18 @@ impl ShellManager {
|
||||
args: MoveArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
let env = self.shells.lock().unwrap();
|
||||
let env = self.shells.lock();
|
||||
|
||||
env[self.current_shell].mv(args, context)
|
||||
match env {
|
||||
Ok(x) => {
|
||||
let path = x[self.current_shell].path();
|
||||
x[self.current_shell].mv(args, context.name, &path)
|
||||
}
|
||||
Err(e) => Err(ShellError::labeled_error(
|
||||
format!("Internal error: could not lock {}", e),
|
||||
"Internal error: could not lock",
|
||||
context.name,
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::commands::command::{EvaluatedWholeStreamCommandArgs, RunnablePerItemContext};
|
||||
use crate::commands::command::EvaluatedWholeStreamCommandArgs;
|
||||
use crate::commands::cp::CopyArgs;
|
||||
use crate::commands::mkdir::MkdirArgs;
|
||||
use crate::commands::mv::MoveArgs;
|
||||
@ -106,48 +106,52 @@ impl Shell for ValueShell {
|
||||
fn cp(
|
||||
&self,
|
||||
_args: CopyArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
_path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
Err(ShellError::labeled_error(
|
||||
"cp not currently supported on values",
|
||||
"not currently supported",
|
||||
context.name,
|
||||
name,
|
||||
))
|
||||
}
|
||||
|
||||
fn mv(
|
||||
&self,
|
||||
_args: MoveArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
_path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
Err(ShellError::labeled_error(
|
||||
"mv not currently supported on values",
|
||||
"not currently supported",
|
||||
context.name,
|
||||
name,
|
||||
))
|
||||
}
|
||||
|
||||
fn mkdir(
|
||||
&self,
|
||||
_args: MkdirArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
_path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
Err(ShellError::labeled_error(
|
||||
"mkdir not currently supported on values",
|
||||
"not currently supported",
|
||||
context.name,
|
||||
name,
|
||||
))
|
||||
}
|
||||
|
||||
fn rm(
|
||||
&self,
|
||||
_args: RemoveArgs,
|
||||
context: &RunnablePerItemContext,
|
||||
name: Span,
|
||||
_path: &str,
|
||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
||||
Err(ShellError::labeled_error(
|
||||
"rm not currently supported on values",
|
||||
"not currently supported",
|
||||
context.name,
|
||||
name,
|
||||
))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user