mirror of
https://github.com/nushell/nushell
synced 2025-01-14 22:24:54 +00:00
Merge pull request #397 from jonathandturner/surf
switch from reqwest to surf
This commit is contained in:
commit
5a355683ad
18 changed files with 430 additions and 761 deletions
|
@ -6,7 +6,7 @@ strategy:
|
||||||
linux-nightly:
|
linux-nightly:
|
||||||
image: ubuntu-16.04
|
image: ubuntu-16.04
|
||||||
macos-nightly:
|
macos-nightly:
|
||||||
image: macos-10.13
|
image: macos-10.14
|
||||||
windows-nightly:
|
windows-nightly:
|
||||||
image: vs2017-win2016
|
image: vs2017-win2016
|
||||||
|
|
||||||
|
|
867
Cargo.lock
generated
867
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -28,8 +28,8 @@ chrono-humanize = "0.0.11"
|
||||||
byte-unit = "3.0.1"
|
byte-unit = "3.0.1"
|
||||||
ordered-float = {version = "1.0.2", features = ["serde"]}
|
ordered-float = {version = "1.0.2", features = ["serde"]}
|
||||||
prettyprint = "0.7.0"
|
prettyprint = "0.7.0"
|
||||||
futures-preview = { version = "=0.3.0-alpha.18", features = ["compat", "io-compat"] }
|
futures-preview = { version = "=0.3.0-alpha.17", features = ["compat", "io-compat"] }
|
||||||
futures-sink-preview = "=0.3.0-alpha.18"
|
futures-sink-preview = "=0.3.0-alpha.17"
|
||||||
futures-async-stream = "0.1.0-alpha.1"
|
futures-async-stream = "0.1.0-alpha.1"
|
||||||
futures_codec = "0.2.5"
|
futures_codec = "0.2.5"
|
||||||
term = "0.5.2"
|
term = "0.5.2"
|
||||||
|
@ -52,7 +52,8 @@ dirs = "2.0.2"
|
||||||
glob = "0.3.0"
|
glob = "0.3.0"
|
||||||
ctrlc = "3.1.3"
|
ctrlc = "3.1.3"
|
||||||
ptree = "0.2"
|
ptree = "0.2"
|
||||||
reqwest = "0.9"
|
surf = "1.0"
|
||||||
|
url = "2.1.0"
|
||||||
roxmltree = "0.7.0"
|
roxmltree = "0.7.0"
|
||||||
nom5_locate = "0.1.1"
|
nom5_locate = "0.1.1"
|
||||||
enum-utils = "0.1.1"
|
enum-utils = "0.1.1"
|
||||||
|
|
|
@ -166,7 +166,8 @@ impl InternalCommand {
|
||||||
&full_path,
|
&full_path,
|
||||||
&location,
|
&location,
|
||||||
Span::unknown(),
|
Span::unknown(),
|
||||||
)?;
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
if let Some(uuid) = contents_tag.origin {
|
if let Some(uuid) = contents_tag.origin {
|
||||||
// If we have loaded something, track its source
|
// If we have loaded something, track its source
|
||||||
|
|
|
@ -81,7 +81,7 @@ impl CallInfo {
|
||||||
pub fn process<'de, T: Deserialize<'de>>(
|
pub fn process<'de, T: Deserialize<'de>>(
|
||||||
&self,
|
&self,
|
||||||
shell_manager: &ShellManager,
|
shell_manager: &ShellManager,
|
||||||
callback: fn(T, &RunnablePerItemContext) -> Result<VecDeque<ReturnValue>, ShellError>,
|
callback: fn(T, &RunnablePerItemContext) -> Result<OutputStream, ShellError>,
|
||||||
) -> Result<RunnablePerItemArgs<T>, ShellError> {
|
) -> Result<RunnablePerItemArgs<T>, ShellError> {
|
||||||
let mut deserializer = ConfigDeserializer::from_call_info(self.clone());
|
let mut deserializer = ConfigDeserializer::from_call_info(self.clone());
|
||||||
|
|
||||||
|
@ -250,11 +250,11 @@ impl RunnableContext {
|
||||||
pub struct RunnablePerItemArgs<T> {
|
pub struct RunnablePerItemArgs<T> {
|
||||||
args: T,
|
args: T,
|
||||||
context: RunnablePerItemContext,
|
context: RunnablePerItemContext,
|
||||||
callback: fn(T, &RunnablePerItemContext) -> Result<VecDeque<ReturnValue>, ShellError>,
|
callback: fn(T, &RunnablePerItemContext) -> Result<OutputStream, ShellError>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> RunnablePerItemArgs<T> {
|
impl<T> RunnablePerItemArgs<T> {
|
||||||
pub fn run(self) -> Result<VecDeque<ReturnValue>, ShellError> {
|
pub fn run(self) -> Result<OutputStream, ShellError> {
|
||||||
(self.callback)(self.args, &self.context)
|
(self.callback)(self.args, &self.context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ pub trait PerItemCommand: Send + Sync {
|
||||||
registry: &CommandRegistry,
|
registry: &CommandRegistry,
|
||||||
shell_manager: &ShellManager,
|
shell_manager: &ShellManager,
|
||||||
input: Tagged<Value>,
|
input: Tagged<Value>,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError>;
|
) -> Result<OutputStream, ShellError>;
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature {
|
Signature {
|
||||||
|
@ -552,7 +552,7 @@ impl Command {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
match command.run(&call_info, ®istry, &raw_args.shell_manager, x) {
|
match command.run(&call_info, ®istry, &raw_args.shell_manager, x) {
|
||||||
Ok(o) => o,
|
Ok(o) => o,
|
||||||
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]),
|
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]).to_output_stream(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten();
|
.flatten();
|
||||||
|
|
|
@ -21,7 +21,7 @@ impl PerItemCommand for Cpy {
|
||||||
_registry: &CommandRegistry,
|
_registry: &CommandRegistry,
|
||||||
shell_manager: &ShellManager,
|
shell_manager: &ShellManager,
|
||||||
_input: Tagged<Value>,
|
_input: Tagged<Value>,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
call_info.process(shell_manager, cp)?.run()
|
call_info.process(shell_manager, cp)?.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +38,7 @@ impl PerItemCommand for Cpy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cp(
|
fn cp(args: CopyArgs, context: &RunnablePerItemContext) -> Result<OutputStream, ShellError> {
|
||||||
args: CopyArgs,
|
|
||||||
context: &RunnablePerItemContext,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
||||||
let shell_manager = context.shell_manager.clone();
|
let shell_manager = context.shell_manager.clone();
|
||||||
shell_manager.cp(args, context)
|
shell_manager.cp(args, context)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ impl PerItemCommand for Enter {
|
||||||
_registry: ®istry::CommandRegistry,
|
_registry: ®istry::CommandRegistry,
|
||||||
_shell_manager: &ShellManager,
|
_shell_manager: &ShellManager,
|
||||||
_input: Tagged<Value>,
|
_input: Tagged<Value>,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
match call_info.args.expect_nth(0)? {
|
match call_info.args.expect_nth(0)? {
|
||||||
Tagged {
|
Tagged {
|
||||||
item: Value::Primitive(Primitive::String(location)),
|
item: Value::Primitive(Primitive::String(location)),
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl PerItemCommand for Mkdir {
|
||||||
_registry: &CommandRegistry,
|
_registry: &CommandRegistry,
|
||||||
shell_manager: &ShellManager,
|
shell_manager: &ShellManager,
|
||||||
_input: Tagged<Value>,
|
_input: Tagged<Value>,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
call_info.process(shell_manager, mkdir)?.run()
|
call_info.process(shell_manager, mkdir)?.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,10 +31,7 @@ impl PerItemCommand for Mkdir {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mkdir(
|
fn mkdir(args: MkdirArgs, context: &RunnablePerItemContext) -> Result<OutputStream, ShellError> {
|
||||||
args: MkdirArgs,
|
|
||||||
context: &RunnablePerItemContext,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
||||||
let shell_manager = context.shell_manager.clone();
|
let shell_manager = context.shell_manager.clone();
|
||||||
shell_manager.mkdir(args, context)
|
shell_manager.mkdir(args, context)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,15 +31,12 @@ impl PerItemCommand for Move {
|
||||||
_registry: &CommandRegistry,
|
_registry: &CommandRegistry,
|
||||||
shell_manager: &ShellManager,
|
shell_manager: &ShellManager,
|
||||||
_input: Tagged<Value>,
|
_input: Tagged<Value>,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
call_info.process(shell_manager, mv)?.run()
|
call_info.process(shell_manager, mv)?.run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mv(
|
fn mv(args: MoveArgs, context: &RunnablePerItemContext) -> Result<OutputStream, ShellError> {
|
||||||
args: MoveArgs,
|
|
||||||
context: &RunnablePerItemContext,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
||||||
let shell_manager = context.shell_manager.clone();
|
let shell_manager = context.shell_manager.clone();
|
||||||
shell_manager.mv(args, context)
|
shell_manager.mv(args, context)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::prelude::*;
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use surf::mime;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
pub struct Open;
|
pub struct Open;
|
||||||
|
|
||||||
|
@ -27,15 +28,12 @@ impl PerItemCommand for Open {
|
||||||
_registry: &CommandRegistry,
|
_registry: &CommandRegistry,
|
||||||
shell_manager: &ShellManager,
|
shell_manager: &ShellManager,
|
||||||
_input: Tagged<Value>,
|
_input: Tagged<Value>,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
run(call_info, shell_manager)
|
run(call_info, shell_manager)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(
|
fn run(call_info: &CallInfo, shell_manager: &ShellManager) -> Result<OutputStream, ShellError> {
|
||||||
call_info: &CallInfo,
|
|
||||||
shell_manager: &ShellManager,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
||||||
let cwd = PathBuf::from(shell_manager.path());
|
let cwd = PathBuf::from(shell_manager.path());
|
||||||
let full_path = PathBuf::from(cwd);
|
let full_path = PathBuf::from(cwd);
|
||||||
|
|
||||||
|
@ -46,85 +44,101 @@ fn run(
|
||||||
{
|
{
|
||||||
file => file,
|
file => file,
|
||||||
};
|
};
|
||||||
|
|
||||||
let path_str = path.as_string()?;
|
let path_str = path.as_string()?;
|
||||||
|
let path_span = path.span();
|
||||||
|
let name_span = call_info.name_span;
|
||||||
|
let has_raw = call_info.args.has("raw");
|
||||||
|
|
||||||
let (file_extension, contents, contents_tag, span_source) =
|
let stream = async_stream_block! {
|
||||||
fetch(&full_path, &path_str, path.span())?;
|
|
||||||
|
|
||||||
let file_extension = if call_info.args.has("raw") {
|
//FIXME: unwraps
|
||||||
None
|
|
||||||
} else {
|
|
||||||
file_extension
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut stream = VecDeque::new();
|
let (file_extension, contents, contents_tag, span_source) =
|
||||||
|
fetch(&full_path, &path_str, path_span).await.unwrap();
|
||||||
|
|
||||||
if let Some(uuid) = contents_tag.origin {
|
let file_extension = if has_raw {
|
||||||
// If we have loaded something, track its source
|
None
|
||||||
stream.push_back(ReturnSuccess::action(CommandAction::AddSpanSource(
|
} else {
|
||||||
uuid,
|
file_extension
|
||||||
span_source,
|
};
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
match contents {
|
if let Some(uuid) = contents_tag.origin {
|
||||||
Value::Primitive(Primitive::String(string)) => {
|
// If we have loaded something, track its source
|
||||||
let value = parse_as_value(file_extension, string, contents_tag, call_info.name_span)?;
|
yield ReturnSuccess::action(CommandAction::AddSpanSource(
|
||||||
|
uuid,
|
||||||
match value {
|
span_source,
|
||||||
Tagged {
|
));
|
||||||
item: Value::List(list),
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
for elem in list {
|
|
||||||
stream.push_back(ReturnSuccess::value(elem));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
x => stream.push_back(ReturnSuccess::value(x)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
other => stream.push_back(ReturnSuccess::value(other.tagged(contents_tag))),
|
match contents {
|
||||||
|
Value::Primitive(Primitive::String(string)) => {
|
||||||
|
let value = parse_as_value(file_extension, string, contents_tag, name_span).unwrap();
|
||||||
|
|
||||||
|
match value {
|
||||||
|
Tagged {
|
||||||
|
item: Value::List(list),
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
for elem in list {
|
||||||
|
yield ReturnSuccess::value(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x => yield ReturnSuccess::value(x),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
other => yield ReturnSuccess::value(other.tagged(contents_tag)),
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(stream)
|
Ok(stream.to_output_stream())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch(
|
pub async fn fetch(
|
||||||
cwd: &PathBuf,
|
cwd: &PathBuf,
|
||||||
location: &str,
|
location: &str,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Result<(Option<String>, Value, Tag, SpanSource), ShellError> {
|
) -> Result<(Option<String>, Value, Tag, SpanSource), ShellError> {
|
||||||
let mut cwd = cwd.clone();
|
let mut cwd = cwd.clone();
|
||||||
if location.starts_with("http:") || location.starts_with("https:") {
|
if location.starts_with("http:") || location.starts_with("https:") {
|
||||||
let response = reqwest::get(location);
|
let response = surf::get(location).await;
|
||||||
match response {
|
match response {
|
||||||
Ok(mut r) => match r.headers().get("content-type") {
|
Ok(mut r) => match r.headers().get("content-type") {
|
||||||
Some(content_type) => {
|
Some(content_type) => {
|
||||||
let content_type = Mime::from_str(content_type.to_str().unwrap()).unwrap();
|
let content_type = Mime::from_str(content_type).unwrap();
|
||||||
match (content_type.type_(), content_type.subtype()) {
|
match (content_type.type_(), content_type.subtype()) {
|
||||||
(mime::APPLICATION, mime::XML) => Ok((
|
(mime::APPLICATION, mime::XML) => Ok((
|
||||||
Some("xml".to_string()),
|
Some("xml".to_string()),
|
||||||
Value::string(r.text().unwrap()),
|
Value::string(r.body_string().await.map_err(|_| {
|
||||||
|
ShellError::labeled_error(
|
||||||
|
"Could not load text from remote url",
|
||||||
|
"could not load",
|
||||||
|
span,
|
||||||
|
)
|
||||||
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Some(Uuid::new_v4()),
|
origin: Some(Uuid::new_v4()),
|
||||||
},
|
},
|
||||||
SpanSource::Url(r.url().to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::APPLICATION, mime::JSON) => Ok((
|
(mime::APPLICATION, mime::JSON) => Ok((
|
||||||
Some("json".to_string()),
|
Some("json".to_string()),
|
||||||
Value::string(r.text().unwrap()),
|
Value::string(r.body_string().await.map_err(|_| {
|
||||||
|
ShellError::labeled_error(
|
||||||
|
"Could not load text from remote url",
|
||||||
|
"could not load",
|
||||||
|
span,
|
||||||
|
)
|
||||||
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Some(Uuid::new_v4()),
|
origin: Some(Uuid::new_v4()),
|
||||||
},
|
},
|
||||||
SpanSource::Url(r.url().to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::APPLICATION, mime::OCTET_STREAM) => {
|
(mime::APPLICATION, mime::OCTET_STREAM) => {
|
||||||
let mut buf: Vec<u8> = vec![];
|
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
||||||
r.copy_to(&mut buf).map_err(|_| {
|
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load binary file",
|
"Could not load binary file",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -138,12 +152,11 @@ pub fn fetch(
|
||||||
span,
|
span,
|
||||||
origin: Some(Uuid::new_v4()),
|
origin: Some(Uuid::new_v4()),
|
||||||
},
|
},
|
||||||
SpanSource::Url(r.url().to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(mime::IMAGE, image_ty) => {
|
(mime::IMAGE, image_ty) => {
|
||||||
let mut buf: Vec<u8> = vec![];
|
let buf: Vec<u8> = r.body_bytes().await.map_err(|_| {
|
||||||
r.copy_to(&mut buf).map_err(|_| {
|
|
||||||
ShellError::labeled_error(
|
ShellError::labeled_error(
|
||||||
"Could not load image file",
|
"Could not load image file",
|
||||||
"could not load",
|
"could not load",
|
||||||
|
@ -157,21 +170,27 @@ pub fn fetch(
|
||||||
span,
|
span,
|
||||||
origin: Some(Uuid::new_v4()),
|
origin: Some(Uuid::new_v4()),
|
||||||
},
|
},
|
||||||
SpanSource::Url(r.url().to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(mime::TEXT, mime::HTML) => Ok((
|
(mime::TEXT, mime::HTML) => Ok((
|
||||||
Some("html".to_string()),
|
Some("html".to_string()),
|
||||||
Value::string(r.text().unwrap()),
|
Value::string(r.body_string().await.map_err(|_| {
|
||||||
|
ShellError::labeled_error(
|
||||||
|
"Could not load text from remote url",
|
||||||
|
"could not load",
|
||||||
|
span,
|
||||||
|
)
|
||||||
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Some(Uuid::new_v4()),
|
origin: Some(Uuid::new_v4()),
|
||||||
},
|
},
|
||||||
SpanSource::Url(r.url().to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
(mime::TEXT, mime::PLAIN) => {
|
(mime::TEXT, mime::PLAIN) => {
|
||||||
let path_extension = r
|
let path_extension = url::Url::parse(location)
|
||||||
.url()
|
.unwrap()
|
||||||
.path_segments()
|
.path_segments()
|
||||||
.and_then(|segments| segments.last())
|
.and_then(|segments| segments.last())
|
||||||
.and_then(|name| if name.is_empty() { None } else { Some(name) })
|
.and_then(|name| if name.is_empty() { None } else { Some(name) })
|
||||||
|
@ -183,12 +202,18 @@ pub fn fetch(
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
path_extension,
|
path_extension,
|
||||||
Value::string(r.text().unwrap()),
|
Value::string(r.body_string().await.map_err(|_| {
|
||||||
|
ShellError::labeled_error(
|
||||||
|
"Could not load text from remote url",
|
||||||
|
"could not load",
|
||||||
|
span,
|
||||||
|
)
|
||||||
|
})?),
|
||||||
Tag {
|
Tag {
|
||||||
span,
|
span,
|
||||||
origin: Some(Uuid::new_v4()),
|
origin: Some(Uuid::new_v4()),
|
||||||
},
|
},
|
||||||
SpanSource::Url(r.url().to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
(ty, sub_ty) => Ok((
|
(ty, sub_ty) => Ok((
|
||||||
|
@ -201,7 +226,7 @@ pub fn fetch(
|
||||||
span,
|
span,
|
||||||
origin: Some(Uuid::new_v4()),
|
origin: Some(Uuid::new_v4()),
|
||||||
},
|
},
|
||||||
SpanSource::Url(r.url().to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,7 +237,7 @@ pub fn fetch(
|
||||||
span,
|
span,
|
||||||
origin: Some(Uuid::new_v4()),
|
origin: Some(Uuid::new_v4()),
|
||||||
},
|
},
|
||||||
SpanSource::Url(r.url().to_string()),
|
SpanSource::Url(location.to_string()),
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
|
@ -30,15 +30,12 @@ impl PerItemCommand for Remove {
|
||||||
_registry: &CommandRegistry,
|
_registry: &CommandRegistry,
|
||||||
shell_manager: &ShellManager,
|
shell_manager: &ShellManager,
|
||||||
_input: Tagged<Value>,
|
_input: Tagged<Value>,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
call_info.process(shell_manager, rm)?.run()
|
call_info.process(shell_manager, rm)?.run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rm(
|
fn rm(args: RemoveArgs, context: &RunnablePerItemContext) -> Result<OutputStream, ShellError> {
|
||||||
args: RemoveArgs,
|
|
||||||
context: &RunnablePerItemContext,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
||||||
let shell_manager = context.shell_manager.clone();
|
let shell_manager = context.shell_manager.clone();
|
||||||
shell_manager.rm(args, context)
|
shell_manager.rm(args, context)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ impl PerItemCommand for Where {
|
||||||
_registry: ®istry::CommandRegistry,
|
_registry: ®istry::CommandRegistry,
|
||||||
_shell_manager: &ShellManager,
|
_shell_manager: &ShellManager,
|
||||||
input: Tagged<Value>,
|
input: Tagged<Value>,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let input_clone = input.clone();
|
let input_clone = input.clone();
|
||||||
let condition = call_info.args.expect_nth(0)?;
|
let condition = call_info.args.expect_nth(0)?;
|
||||||
match condition {
|
let stream = match condition {
|
||||||
Tagged {
|
Tagged {
|
||||||
item: Value::Block(block),
|
item: Value::Block(block),
|
||||||
tag,
|
tag,
|
||||||
|
@ -33,23 +33,29 @@ impl PerItemCommand for Where {
|
||||||
match result {
|
match result {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
if v.is_true() {
|
if v.is_true() {
|
||||||
Ok(VecDeque::from(vec![Ok(ReturnSuccess::Value(input_clone))]))
|
VecDeque::from(vec![Ok(ReturnSuccess::Value(input_clone))])
|
||||||
} else {
|
} else {
|
||||||
Ok(VecDeque::new())
|
VecDeque::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => Err(ShellError::labeled_error(
|
Err(e) => {
|
||||||
format!("Could not evaluate ({})", e.to_string()),
|
return Err(ShellError::labeled_error(
|
||||||
"could not evaluate",
|
format!("Could not evaluate ({})", e.to_string()),
|
||||||
tag.span,
|
"could not evaluate",
|
||||||
)),
|
tag.span,
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Tagged { tag, .. } => Err(ShellError::labeled_error(
|
Tagged { tag, .. } => {
|
||||||
"Expected a condition",
|
return Err(ShellError::labeled_error(
|
||||||
"where needs a condition",
|
"Expected a condition",
|
||||||
tag.span,
|
"where needs a condition",
|
||||||
)),
|
tag.span,
|
||||||
}
|
))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(stream.to_output_stream())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -451,7 +451,6 @@ impl std::convert::From<serde_yaml::Error> for ShellError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl std::convert::From<toml::ser::Error> for ShellError {
|
impl std::convert::From<toml::ser::Error> for ShellError {
|
||||||
fn from(input: toml::ser::Error) -> ShellError {
|
fn from(input: toml::ser::Error) -> ShellError {
|
||||||
ProximateShellError::String(StringError {
|
ProximateShellError::String(StringError {
|
||||||
|
@ -482,6 +481,16 @@ impl std::convert::From<regex::Error> for ShellError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::convert::From<Box<dyn std::error::Error + Send + Sync>> for ShellError {
|
||||||
|
fn from(input: Box<dyn std::error::Error + Send + Sync>) -> ShellError {
|
||||||
|
ProximateShellError::String(StringError {
|
||||||
|
title: format!("{:?}", input),
|
||||||
|
error: Value::nothing(),
|
||||||
|
})
|
||||||
|
.start()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait ShellErrorUtils<T> {
|
pub trait ShellErrorUtils<T> {
|
||||||
fn unwrap_error(self, desc: impl Into<String>) -> Result<T, ShellError>;
|
fn unwrap_error(self, desc: impl Into<String>) -> Result<T, ShellError>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,7 +308,7 @@ fn view_text_value(value: &Tagged<Value>, source_map: &SourceMap) {
|
||||||
path.extension().map(|x| x.to_string_lossy().to_string())
|
path.extension().map(|x| x.to_string_lossy().to_string())
|
||||||
}
|
}
|
||||||
SpanSource::Url(url) => {
|
SpanSource::Url(url) => {
|
||||||
let url = reqwest::Url::parse(url);
|
let url = url::Url::parse(url);
|
||||||
if let Ok(url) = url {
|
if let Ok(url) = url {
|
||||||
let url = url.clone();
|
let url = url.clone();
|
||||||
if let Some(mut segments) = url.path_segments() {
|
if let Some(mut segments) = url.path_segments() {
|
||||||
|
|
|
@ -221,7 +221,7 @@ impl Shell for FilesystemShell {
|
||||||
}: CopyArgs,
|
}: CopyArgs,
|
||||||
name: Span,
|
name: Span,
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let name_span = name;
|
let name_span = name;
|
||||||
|
|
||||||
let mut source = PathBuf::from(path);
|
let mut source = PathBuf::from(path);
|
||||||
|
@ -491,7 +491,7 @@ impl Shell for FilesystemShell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(VecDeque::new())
|
Ok(OutputStream::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mkdir(
|
fn mkdir(
|
||||||
|
@ -504,7 +504,7 @@ impl Shell for FilesystemShell {
|
||||||
// }: &RunnablePerItemContext,
|
// }: &RunnablePerItemContext,
|
||||||
name: Span,
|
name: Span,
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let full_path = PathBuf::from(path);
|
let full_path = PathBuf::from(path);
|
||||||
|
|
||||||
if directories.len() == 0 {
|
if directories.len() == 0 {
|
||||||
|
@ -534,7 +534,7 @@ impl Shell for FilesystemShell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(VecDeque::new())
|
Ok(OutputStream::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mv(
|
fn mv(
|
||||||
|
@ -542,7 +542,7 @@ impl Shell for FilesystemShell {
|
||||||
MoveArgs { src, dst }: MoveArgs,
|
MoveArgs { src, dst }: MoveArgs,
|
||||||
name: Span,
|
name: Span,
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let name_span = name;
|
let name_span = name;
|
||||||
|
|
||||||
let mut source = PathBuf::from(path);
|
let mut source = PathBuf::from(path);
|
||||||
|
@ -837,7 +837,7 @@ impl Shell for FilesystemShell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(VecDeque::new())
|
Ok(OutputStream::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rm(
|
fn rm(
|
||||||
|
@ -845,7 +845,7 @@ impl Shell for FilesystemShell {
|
||||||
RemoveArgs { target, recursive }: RemoveArgs,
|
RemoveArgs { target, recursive }: RemoveArgs,
|
||||||
name: Span,
|
name: Span,
|
||||||
path: &str,
|
path: &str,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let name_span = name;
|
let name_span = name;
|
||||||
|
|
||||||
if target.item.to_str() == Some(".") || target.item.to_str() == Some("..") {
|
if target.item.to_str() == Some(".") || target.item.to_str() == Some("..") {
|
||||||
|
@ -941,7 +941,7 @@ impl Shell for FilesystemShell {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(VecDeque::new())
|
Ok(OutputStream::empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path(&self) -> String {
|
fn path(&self) -> String {
|
||||||
|
|
|
@ -12,30 +12,10 @@ pub trait Shell: std::fmt::Debug {
|
||||||
fn name(&self, source_map: &SourceMap) -> String;
|
fn name(&self, source_map: &SourceMap) -> String;
|
||||||
fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError>;
|
fn ls(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError>;
|
||||||
fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError>;
|
fn cd(&self, args: EvaluatedWholeStreamCommandArgs) -> Result<OutputStream, ShellError>;
|
||||||
fn cp(
|
fn cp(&self, args: CopyArgs, name: Span, path: &str) -> Result<OutputStream, ShellError>;
|
||||||
&self,
|
fn mkdir(&self, args: MkdirArgs, name: Span, path: &str) -> Result<OutputStream, ShellError>;
|
||||||
args: CopyArgs,
|
fn mv(&self, args: MoveArgs, name: Span, path: &str) -> Result<OutputStream, ShellError>;
|
||||||
name: Span,
|
fn rm(&self, args: RemoveArgs, name: Span, path: &str) -> Result<OutputStream, ShellError>;
|
||||||
path: &str,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError>;
|
|
||||||
fn mkdir(
|
|
||||||
&self,
|
|
||||||
args: MkdirArgs,
|
|
||||||
name: Span,
|
|
||||||
path: &str,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError>;
|
|
||||||
fn mv(
|
|
||||||
&self,
|
|
||||||
args: MoveArgs,
|
|
||||||
name: Span,
|
|
||||||
path: &str,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError>;
|
|
||||||
fn rm(
|
|
||||||
&self,
|
|
||||||
args: RemoveArgs,
|
|
||||||
name: Span,
|
|
||||||
path: &str,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError>;
|
|
||||||
fn path(&self) -> String;
|
fn path(&self) -> String;
|
||||||
fn set_path(&mut self, path: String);
|
fn set_path(&mut self, path: String);
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ impl ShellManager {
|
||||||
&self,
|
&self,
|
||||||
args: CopyArgs,
|
args: CopyArgs,
|
||||||
context: &RunnablePerItemContext,
|
context: &RunnablePerItemContext,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let env = self.shells.lock();
|
let env = self.shells.lock();
|
||||||
|
|
||||||
match env {
|
match env {
|
||||||
|
@ -136,7 +136,7 @@ impl ShellManager {
|
||||||
&self,
|
&self,
|
||||||
args: RemoveArgs,
|
args: RemoveArgs,
|
||||||
context: &RunnablePerItemContext,
|
context: &RunnablePerItemContext,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let env = self.shells.lock();
|
let env = self.shells.lock();
|
||||||
|
|
||||||
match env {
|
match env {
|
||||||
|
@ -156,7 +156,7 @@ impl ShellManager {
|
||||||
&self,
|
&self,
|
||||||
args: MkdirArgs,
|
args: MkdirArgs,
|
||||||
context: &RunnablePerItemContext,
|
context: &RunnablePerItemContext,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let env = self.shells.lock();
|
let env = self.shells.lock();
|
||||||
|
|
||||||
match env {
|
match env {
|
||||||
|
@ -176,7 +176,7 @@ impl ShellManager {
|
||||||
&self,
|
&self,
|
||||||
args: MoveArgs,
|
args: MoveArgs,
|
||||||
context: &RunnablePerItemContext,
|
context: &RunnablePerItemContext,
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let env = self.shells.lock();
|
let env = self.shells.lock();
|
||||||
|
|
||||||
match env {
|
match env {
|
||||||
|
|
|
@ -103,12 +103,7 @@ impl Shell for ValueShell {
|
||||||
Ok(stream.into())
|
Ok(stream.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cp(
|
fn cp(&self, _args: CopyArgs, name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||||
&self,
|
|
||||||
_args: CopyArgs,
|
|
||||||
name: Span,
|
|
||||||
_path: &str,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
||||||
Err(ShellError::labeled_error(
|
Err(ShellError::labeled_error(
|
||||||
"cp not currently supported on values",
|
"cp not currently supported on values",
|
||||||
"not currently supported",
|
"not currently supported",
|
||||||
|
@ -116,12 +111,7 @@ impl Shell for ValueShell {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mv(
|
fn mv(&self, _args: MoveArgs, name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||||
&self,
|
|
||||||
_args: MoveArgs,
|
|
||||||
name: Span,
|
|
||||||
_path: &str,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
||||||
Err(ShellError::labeled_error(
|
Err(ShellError::labeled_error(
|
||||||
"mv not currently supported on values",
|
"mv not currently supported on values",
|
||||||
"not currently supported",
|
"not currently supported",
|
||||||
|
@ -129,12 +119,7 @@ impl Shell for ValueShell {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mkdir(
|
fn mkdir(&self, _args: MkdirArgs, name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||||
&self,
|
|
||||||
_args: MkdirArgs,
|
|
||||||
name: Span,
|
|
||||||
_path: &str,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
||||||
Err(ShellError::labeled_error(
|
Err(ShellError::labeled_error(
|
||||||
"mkdir not currently supported on values",
|
"mkdir not currently supported on values",
|
||||||
"not currently supported",
|
"not currently supported",
|
||||||
|
@ -142,12 +127,7 @@ impl Shell for ValueShell {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rm(
|
fn rm(&self, _args: RemoveArgs, name: Span, _path: &str) -> Result<OutputStream, ShellError> {
|
||||||
&self,
|
|
||||||
_args: RemoveArgs,
|
|
||||||
name: Span,
|
|
||||||
_path: &str,
|
|
||||||
) -> Result<VecDeque<ReturnValue>, ShellError> {
|
|
||||||
Err(ShellError::labeled_error(
|
Err(ShellError::labeled_error(
|
||||||
"rm not currently supported on values",
|
"rm not currently supported on values",
|
||||||
"not currently supported",
|
"not currently supported",
|
||||||
|
|
Loading…
Reference in a new issue