mirror of
https://github.com/nushell/nushell.git
synced 2025-08-13 13:37:47 +02:00
Revert "Revert "Migrate most uses of the Span concept to Tag""
This reverts commit bee7c5639c
.
This commit is contained in:
@ -81,23 +81,27 @@ impl Shell for FilesystemShell {
|
||||
dirs::home_dir()
|
||||
}
|
||||
|
||||
fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn ls(
|
||||
&self,
|
||||
pattern: Option<Tagged<PathBuf>>,
|
||||
command_tag: Tag,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let cwd = self.path();
|
||||
let mut full_path = PathBuf::from(self.path());
|
||||
|
||||
match &args.nth(0) {
|
||||
Some(value) => full_path.push(Path::new(&value.as_path()?)),
|
||||
match &pattern {
|
||||
Some(value) => full_path.push((*value).as_ref()),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let entries: Vec<_> = match glob::glob(&full_path.to_string_lossy()) {
|
||||
Ok(files) => files.collect(),
|
||||
Err(_) => {
|
||||
if let Some(source) = args.nth(0) {
|
||||
if let Some(source) = pattern {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Invalid pattern",
|
||||
"Invalid pattern",
|
||||
source.span(),
|
||||
source.tag(),
|
||||
));
|
||||
} else {
|
||||
return Err(ShellError::string("Invalid pattern."));
|
||||
@ -114,17 +118,17 @@ impl Shell for FilesystemShell {
|
||||
let entries = std::fs::read_dir(&entry);
|
||||
let entries = match entries {
|
||||
Err(e) => {
|
||||
if let Some(s) = args.nth(0) {
|
||||
if let Some(s) = pattern {
|
||||
return Err(ShellError::labeled_error(
|
||||
e.to_string(),
|
||||
e.to_string(),
|
||||
s.span(),
|
||||
s.tag(),
|
||||
));
|
||||
} else {
|
||||
return Err(ShellError::labeled_error(
|
||||
e.to_string(),
|
||||
e.to_string(),
|
||||
args.name_span(),
|
||||
command_tag,
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -138,11 +142,7 @@ impl Shell for FilesystemShell {
|
||||
} else {
|
||||
Path::new(&filepath)
|
||||
};
|
||||
let value = dir_entry_dict(
|
||||
filename,
|
||||
&entry.metadata()?,
|
||||
Tag::unknown_origin(args.call_info.name_span),
|
||||
)?;
|
||||
let value = dir_entry_dict(filename, &entry.metadata()?, command_tag)?;
|
||||
shell_entries.push_back(ReturnSuccess::value(value))
|
||||
}
|
||||
return Ok(shell_entries.to_output_stream());
|
||||
@ -159,11 +159,7 @@ impl Shell for FilesystemShell {
|
||||
Path::new(&entry)
|
||||
};
|
||||
let metadata = std::fs::metadata(&entry)?;
|
||||
let value = dir_entry_dict(
|
||||
filename,
|
||||
&metadata,
|
||||
Tag::unknown_origin(args.call_info.name_span),
|
||||
)?;
|
||||
let value = dir_entry_dict(filename, &metadata, command_tag)?;
|
||||
shell_entries.push_back(ReturnSuccess::value(value))
|
||||
}
|
||||
}
|
||||
@ -179,7 +175,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Can not change to home directory",
|
||||
"can not go to home",
|
||||
args.call_info.name_span,
|
||||
args.call_info.name_tag,
|
||||
))
|
||||
}
|
||||
},
|
||||
@ -197,7 +193,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Can not change to directory",
|
||||
"directory not found",
|
||||
v.span().clone(),
|
||||
v.tag().clone(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -221,10 +217,10 @@ impl Shell for FilesystemShell {
|
||||
dst,
|
||||
recursive,
|
||||
}: CopyArgs,
|
||||
name: Span,
|
||||
name: Tag,
|
||||
path: &str,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let name_span = name;
|
||||
let name_tag = name;
|
||||
|
||||
let mut source = PathBuf::from(path);
|
||||
let mut destination = PathBuf::from(path);
|
||||
@ -279,7 +275,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
e.to_string(),
|
||||
e.to_string(),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -295,7 +291,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
e.to_string(),
|
||||
e.to_string(),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -331,7 +327,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
e.to_string(),
|
||||
e.to_string(),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -345,7 +341,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
e.to_string(),
|
||||
e.to_string(),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -359,7 +355,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Copy aborted. Not a valid path",
|
||||
"Copy aborted. Not a valid path",
|
||||
name_span,
|
||||
name_tag,
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -369,7 +365,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
e.to_string(),
|
||||
e.to_string(),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -405,7 +401,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
e.to_string(),
|
||||
e.to_string(),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -419,7 +415,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
e.to_string(),
|
||||
e.to_string(),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -452,7 +448,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Copy aborted. Not a valid path",
|
||||
"Copy aborted. Not a valid path",
|
||||
name_span,
|
||||
name_tag,
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -479,7 +475,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Copy aborted. Not a valid destination",
|
||||
"Copy aborted. Not a valid destination",
|
||||
name_span,
|
||||
name_tag,
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -488,7 +484,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
format!("Copy aborted. (Does {:?} exist?)", destination_file_name),
|
||||
format!("Copy aborted. (Does {:?} exist?)", destination_file_name),
|
||||
&dst.span(),
|
||||
dst.tag(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -499,7 +495,7 @@ impl Shell for FilesystemShell {
|
||||
fn mkdir(
|
||||
&self,
|
||||
MkdirArgs { rest: directories }: MkdirArgs,
|
||||
name: Span,
|
||||
name: Tag,
|
||||
path: &str,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let full_path = PathBuf::from(path);
|
||||
@ -524,7 +520,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
reason.to_string(),
|
||||
reason.to_string(),
|
||||
dir.span(),
|
||||
dir.tag(),
|
||||
))
|
||||
}
|
||||
Ok(_) => {}
|
||||
@ -537,10 +533,10 @@ impl Shell for FilesystemShell {
|
||||
fn mv(
|
||||
&self,
|
||||
MoveArgs { src, dst }: MoveArgs,
|
||||
name: Span,
|
||||
name: Tag,
|
||||
path: &str,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let name_span = name;
|
||||
let name_tag = name;
|
||||
|
||||
let mut source = PathBuf::from(path);
|
||||
let mut destination = PathBuf::from(path);
|
||||
@ -566,7 +562,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Rename aborted. Not a valid destination",
|
||||
"Rename aborted. Not a valid destination",
|
||||
dst.span(),
|
||||
dst.tag(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -580,7 +576,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Rename aborted. Not a valid entry name",
|
||||
"Rename aborted. Not a valid entry name",
|
||||
name_span,
|
||||
name_tag,
|
||||
))
|
||||
}
|
||||
};
|
||||
@ -592,7 +588,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
format!("Rename aborted. {:}", e.to_string()),
|
||||
format!("Rename aborted. {:}", e.to_string()),
|
||||
name_span,
|
||||
name_tag,
|
||||
))
|
||||
}
|
||||
};
|
||||
@ -616,7 +612,7 @@ impl Shell for FilesystemShell {
|
||||
destination_file_name,
|
||||
e.to_string(),
|
||||
),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -639,7 +635,7 @@ impl Shell for FilesystemShell {
|
||||
destination_file_name,
|
||||
e.to_string(),
|
||||
),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -661,7 +657,7 @@ impl Shell for FilesystemShell {
|
||||
destination_file_name,
|
||||
e.to_string(),
|
||||
),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -714,7 +710,7 @@ impl Shell for FilesystemShell {
|
||||
destination_file_name,
|
||||
e.to_string(),
|
||||
),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -738,7 +734,7 @@ impl Shell for FilesystemShell {
|
||||
destination_file_name,
|
||||
e.to_string(),
|
||||
),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -761,7 +757,7 @@ impl Shell for FilesystemShell {
|
||||
destination_file_name,
|
||||
e.to_string(),
|
||||
),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -793,7 +789,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Rename aborted. Not a valid entry name",
|
||||
"Rename aborted. Not a valid entry name",
|
||||
name_span,
|
||||
name_tag,
|
||||
))
|
||||
}
|
||||
};
|
||||
@ -817,7 +813,7 @@ impl Shell for FilesystemShell {
|
||||
destination_file_name,
|
||||
e.to_string(),
|
||||
),
|
||||
name_span,
|
||||
name_tag,
|
||||
));
|
||||
}
|
||||
Ok(o) => o,
|
||||
@ -829,7 +825,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
format!("Rename aborted. (Does {:?} exist?)", destination_file_name),
|
||||
format!("Rename aborted. (Does {:?} exist?)", destination_file_name),
|
||||
dst.span(),
|
||||
dst.tag(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -840,16 +836,16 @@ impl Shell for FilesystemShell {
|
||||
fn rm(
|
||||
&self,
|
||||
RemoveArgs { target, recursive }: RemoveArgs,
|
||||
name: Span,
|
||||
name: Tag,
|
||||
path: &str,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let name_span = name;
|
||||
let name_tag = name;
|
||||
|
||||
if target.item.to_str() == Some(".") || target.item.to_str() == Some("..") {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Remove aborted. \".\" or \"..\" may not be removed.",
|
||||
"Remove aborted. \".\" or \"..\" may not be removed.",
|
||||
target.span(),
|
||||
target.tag(),
|
||||
));
|
||||
}
|
||||
|
||||
@ -881,7 +877,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
format!("{:?} is a directory. Try using \"--recursive\".", file),
|
||||
format!("{:?} is a directory. Try using \"--recursive\".", file),
|
||||
target.span(),
|
||||
target.tag(),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -898,7 +894,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Remove aborted. Not a valid path",
|
||||
"Remove aborted. Not a valid path",
|
||||
name_span,
|
||||
name_tag,
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -918,7 +914,7 @@ impl Shell for FilesystemShell {
|
||||
"Directory {:?} found somewhere inside. Try using \"--recursive\".",
|
||||
path_file_name
|
||||
),
|
||||
target.span(),
|
||||
target.tag(),
|
||||
));
|
||||
}
|
||||
|
||||
@ -932,7 +928,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
format!("Remove aborted. {:}", e.to_string()),
|
||||
format!("Remove aborted. {:}", e.to_string()),
|
||||
name_span,
|
||||
name_tag,
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -953,7 +949,7 @@ impl Shell for FilesystemShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"unable to show current directory",
|
||||
"pwd command failed",
|
||||
args.call_info.name_span,
|
||||
args.call_info.name_tag,
|
||||
));
|
||||
}
|
||||
};
|
||||
@ -961,7 +957,7 @@ impl Shell for FilesystemShell {
|
||||
let mut stream = VecDeque::new();
|
||||
stream.push_back(ReturnSuccess::value(
|
||||
Value::Primitive(Primitive::String(p.to_string_lossy().to_string()))
|
||||
.simple_spanned(args.call_info.name_span),
|
||||
.tagged(args.call_info.name_tag),
|
||||
));
|
||||
|
||||
Ok(stream.into())
|
||||
|
@ -126,7 +126,11 @@ impl Shell for HelpShell {
|
||||
self.path = path.clone();
|
||||
}
|
||||
|
||||
fn ls(&self, _args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn ls(
|
||||
&self,
|
||||
_pattern: Option<Tagged<PathBuf>>,
|
||||
_command_tag: Tag,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
Ok(self
|
||||
.commands()
|
||||
.map(|x| ReturnSuccess::value(x))
|
||||
@ -161,24 +165,19 @@ impl Shell for HelpShell {
|
||||
Ok(stream.into())
|
||||
}
|
||||
|
||||
fn cp(&self, _args: CopyArgs, _name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
fn cp(&self, _args: CopyArgs, _name: Tag, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
Ok(OutputStream::empty())
|
||||
}
|
||||
|
||||
fn mv(&self, _args: MoveArgs, _name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
fn mv(&self, _args: MoveArgs, _name: Tag, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
Ok(OutputStream::empty())
|
||||
}
|
||||
|
||||
fn mkdir(
|
||||
&self,
|
||||
_args: MkdirArgs,
|
||||
_name: Span,
|
||||
_path: &str,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
fn mkdir(&self, _args: MkdirArgs, _name: Tag, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
Ok(OutputStream::empty())
|
||||
}
|
||||
|
||||
fn rm(&self, _args: RemoveArgs, _name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
fn rm(&self, _args: RemoveArgs, _name: Tag, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
Ok(OutputStream::empty())
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ impl Highlighter for Helper {
|
||||
}
|
||||
|
||||
fn highlight<'l>(&self, line: &'l str, _pos: usize) -> Cow<'l, str> {
|
||||
let tokens = crate::parser::pipeline(nom_input(line));
|
||||
let tokens = crate::parser::pipeline(nom_input(line, uuid::Uuid::nil()));
|
||||
|
||||
match tokens {
|
||||
Err(_) => Cow::Borrowed(line),
|
||||
@ -106,47 +106,47 @@ impl Highlighter for Helper {
|
||||
|
||||
fn paint_token_node(token_node: &TokenNode, line: &str) -> String {
|
||||
let styled = match token_node {
|
||||
TokenNode::Call(..) => Color::Cyan.bold().paint(token_node.span().slice(line)),
|
||||
TokenNode::Whitespace(..) => Color::White.normal().paint(token_node.span().slice(line)),
|
||||
TokenNode::Flag(..) => Color::Black.bold().paint(token_node.span().slice(line)),
|
||||
TokenNode::Member(..) => Color::Yellow.bold().paint(token_node.span().slice(line)),
|
||||
TokenNode::Path(..) => Color::Green.bold().paint(token_node.span().slice(line)),
|
||||
TokenNode::Error(..) => Color::Red.bold().paint(token_node.span().slice(line)),
|
||||
TokenNode::Delimited(..) => Color::White.paint(token_node.span().slice(line)),
|
||||
TokenNode::Operator(..) => Color::White.normal().paint(token_node.span().slice(line)),
|
||||
TokenNode::Pipeline(..) => Color::Blue.normal().paint(token_node.span().slice(line)),
|
||||
TokenNode::Call(..) => Color::Cyan.bold().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Whitespace(..) => Color::White.normal().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Flag(..) => Color::Black.bold().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Member(..) => Color::Yellow.bold().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Path(..) => Color::Green.bold().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Error(..) => Color::Red.bold().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Delimited(..) => Color::White.paint(token_node.tag().slice(line)),
|
||||
TokenNode::Operator(..) => Color::White.normal().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Pipeline(..) => Color::Blue.normal().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Token(Tagged {
|
||||
item: RawToken::Number(..),
|
||||
..
|
||||
}) => Color::Purple.bold().paint(token_node.span().slice(line)),
|
||||
}) => Color::Purple.bold().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Token(Tagged {
|
||||
item: RawToken::Size(..),
|
||||
..
|
||||
}) => Color::Purple.bold().paint(token_node.span().slice(line)),
|
||||
}) => Color::Purple.bold().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Token(Tagged {
|
||||
item: RawToken::GlobPattern,
|
||||
..
|
||||
}) => Color::Cyan.normal().paint(token_node.span().slice(line)),
|
||||
}) => Color::Cyan.normal().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Token(Tagged {
|
||||
item: RawToken::String(..),
|
||||
..
|
||||
}) => Color::Green.normal().paint(token_node.span().slice(line)),
|
||||
}) => Color::Green.normal().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Token(Tagged {
|
||||
item: RawToken::Variable(..),
|
||||
..
|
||||
}) => Color::Yellow.bold().paint(token_node.span().slice(line)),
|
||||
}) => Color::Yellow.bold().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Token(Tagged {
|
||||
item: RawToken::Bare,
|
||||
..
|
||||
}) => Color::Green.normal().paint(token_node.span().slice(line)),
|
||||
}) => Color::Green.normal().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Token(Tagged {
|
||||
item: RawToken::ExternalCommand(..),
|
||||
..
|
||||
}) => Color::Cyan.bold().paint(token_node.span().slice(line)),
|
||||
}) => Color::Cyan.bold().paint(token_node.tag().slice(line)),
|
||||
TokenNode::Token(Tagged {
|
||||
item: RawToken::ExternalWord,
|
||||
..
|
||||
}) => Color::Black.bold().paint(token_node.span().slice(line)),
|
||||
}) => Color::Black.bold().paint(token_node.tag().slice(line)),
|
||||
};
|
||||
|
||||
styled.to_string()
|
||||
@ -166,7 +166,7 @@ fn paint_pipeline_element(pipeline_element: &PipelineElement, line: &str) -> Str
|
||||
styled.push_str(
|
||||
&Color::Cyan
|
||||
.bold()
|
||||
.paint(pipeline_element.call().head().span().slice(line))
|
||||
.paint(pipeline_element.call().head().tag().slice(line))
|
||||
.to_string(),
|
||||
);
|
||||
|
||||
|
@ -13,12 +13,16 @@ pub trait Shell: std::fmt::Debug {
|
||||
fn name(&self, source_map: &SourceMap) -> String;
|
||||
fn homedir(&self) -> Option<PathBuf>;
|
||||
|
||||
fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError>;
|
||||
fn ls(
|
||||
&self,
|
||||
pattern: Option<Tagged<PathBuf>>,
|
||||
command_tag: Tag,
|
||||
) -> Result<OutputStream, ShellError>;
|
||||
fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError>;
|
||||
fn cp(&self, args: CopyArgs, name: Span, path: &str) -> Result<OutputStream, ShellError>;
|
||||
fn mkdir(&self, args: MkdirArgs, name: Span, path: &str) -> Result<OutputStream, ShellError>;
|
||||
fn mv(&self, args: MoveArgs, name: Span, path: &str) -> Result<OutputStream, ShellError>;
|
||||
fn rm(&self, args: RemoveArgs, name: Span, path: &str) -> Result<OutputStream, ShellError>;
|
||||
fn cp(&self, args: CopyArgs, name: Tag, path: &str) -> Result<OutputStream, ShellError>;
|
||||
fn mkdir(&self, args: MkdirArgs, name: Tag, path: &str) -> Result<OutputStream, ShellError>;
|
||||
fn mv(&self, args: MoveArgs, name: Tag, path: &str) -> Result<OutputStream, ShellError>;
|
||||
fn rm(&self, args: RemoveArgs, name: Tag, path: &str) -> Result<OutputStream, ShellError>;
|
||||
fn path(&self) -> String;
|
||||
fn pwd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError>;
|
||||
fn set_path(&mut self, path: String);
|
||||
|
@ -115,10 +115,14 @@ impl ShellManager {
|
||||
env[self.current_shell].homedir()
|
||||
}
|
||||
|
||||
pub fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
||||
pub fn ls(
|
||||
&self,
|
||||
path: Option<Tagged<PathBuf>>,
|
||||
command_tag: Tag,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let env = self.shells.lock().unwrap();
|
||||
|
||||
env[self.current_shell].ls(args)
|
||||
env[self.current_shell].ls(path, command_tag)
|
||||
}
|
||||
|
||||
pub fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
||||
|
@ -87,13 +87,15 @@ impl Shell for ValueShell {
|
||||
Some(PathBuf::from("/"))
|
||||
}
|
||||
|
||||
fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError> {
|
||||
fn ls(
|
||||
&self,
|
||||
target: Option<Tagged<PathBuf>>,
|
||||
command_name: Tag,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let mut full_path = PathBuf::from(self.path());
|
||||
|
||||
let target = args.nth(0);
|
||||
|
||||
match target {
|
||||
Some(value) => full_path.push(Path::new(&value.as_path()?)),
|
||||
match &target {
|
||||
Some(value) => full_path.push(value.as_ref()),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -101,18 +103,18 @@ impl Shell for ValueShell {
|
||||
value_system.walk_decorate(&self.value)?;
|
||||
|
||||
if !value_system.exists(&full_path) {
|
||||
if let Some(target) = target {
|
||||
if let Some(target) = &target {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Can not list entries inside",
|
||||
"No such path exists",
|
||||
target.span(),
|
||||
target.tag(),
|
||||
));
|
||||
}
|
||||
|
||||
return Err(ShellError::labeled_error(
|
||||
"Can not list entries inside",
|
||||
"No such path exists",
|
||||
args.call_info.name_span,
|
||||
command_name,
|
||||
));
|
||||
}
|
||||
|
||||
@ -157,14 +159,14 @@ impl Shell for ValueShell {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Can not change to path inside",
|
||||
"No such path exists",
|
||||
destination.span(),
|
||||
destination.tag(),
|
||||
));
|
||||
}
|
||||
|
||||
return Err(ShellError::labeled_error(
|
||||
"Can not change to path inside",
|
||||
"No such path exists",
|
||||
args.call_info.name_span,
|
||||
args.call_info.name_tag,
|
||||
));
|
||||
}
|
||||
|
||||
@ -173,7 +175,7 @@ impl Shell for ValueShell {
|
||||
Ok(stream.into())
|
||||
}
|
||||
|
||||
fn cp(&self, _args: CopyArgs, name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
fn cp(&self, _args: CopyArgs, name: Tag, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
Err(ShellError::labeled_error(
|
||||
"cp not currently supported on values",
|
||||
"not currently supported",
|
||||
@ -181,7 +183,7 @@ impl Shell for ValueShell {
|
||||
))
|
||||
}
|
||||
|
||||
fn mv(&self, _args: MoveArgs, name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
fn mv(&self, _args: MoveArgs, name: Tag, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
Err(ShellError::labeled_error(
|
||||
"mv not currently supported on values",
|
||||
"not currently supported",
|
||||
@ -189,7 +191,7 @@ impl Shell for ValueShell {
|
||||
))
|
||||
}
|
||||
|
||||
fn mkdir(&self, _args: MkdirArgs, name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
fn mkdir(&self, _args: MkdirArgs, name: Tag, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
Err(ShellError::labeled_error(
|
||||
"mkdir not currently supported on values",
|
||||
"not currently supported",
|
||||
@ -197,7 +199,7 @@ impl Shell for ValueShell {
|
||||
))
|
||||
}
|
||||
|
||||
fn rm(&self, _args: RemoveArgs, name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
fn rm(&self, _args: RemoveArgs, name: Tag, _path: &str) -> Result<OutputStream, ShellError> {
|
||||
Err(ShellError::labeled_error(
|
||||
"rm not currently supported on values",
|
||||
"not currently supported",
|
||||
@ -213,7 +215,7 @@ impl Shell for ValueShell {
|
||||
let mut stream = VecDeque::new();
|
||||
stream.push_back(ReturnSuccess::value(Tagged::from_item(
|
||||
Value::string(self.path()),
|
||||
args.call_info.name_span,
|
||||
args.call_info.name_tag,
|
||||
)));
|
||||
Ok(stream.into())
|
||||
}
|
||||
|
Reference in New Issue
Block a user