Merge branch 'master' into fetch_post

This commit is contained in:
Jonathan Turner
2019-12-07 16:53:50 +13:00
57 changed files with 320 additions and 350 deletions

View File

@ -38,7 +38,7 @@ impl Spanned<String> {
pub fn items<'a, U>(
items: impl Iterator<Item = &'a Spanned<String>>,
) -> impl Iterator<Item = &'a str> {
items.into_iter().map(|item| &item.item[..])
items.map(|item| &item.item[..])
}
}
@ -156,7 +156,7 @@ impl<T> Tagged<T> {
Tagged {
item: self.item,
tag: tag,
tag,
}
}

View File

@ -316,7 +316,7 @@ impl DebugDocBuilder {
result = result + item;
}
result.into()
result
}
fn styled(string: impl std::fmt::Display, style: ShellStyle) -> DebugDocBuilder {

View File

@ -108,7 +108,7 @@ pub async fn fetch(
location: &str,
span: Span,
) -> Result<(Option<String>, UntaggedValue, Tag), ShellError> {
if let Err(_) = url::Url::parse(location) {
if url::Url::parse(location).is_err() {
return Err(ShellError::labeled_error(
"Incomplete or incorrect url",
"expected a full url",
@ -254,19 +254,17 @@ pub async fn fetch(
}
None => Ok((
None,
UntaggedValue::string(format!("No content type found")),
UntaggedValue::string("No content type found".to_owned()),
Tag {
span,
anchor: Some(AnchorLocation::Url(location.to_string())),
},
)),
},
Err(_) => {
return Err(ShellError::labeled_error(
"URL could not be opened",
"url not found",
span,
));
}
Err(_) => Err(ShellError::labeled_error(
"URL could not be opened",
"url not found",
span,
)),
}
}

View File

@ -122,7 +122,7 @@ pub async fn post(
body: &Value,
user: Option<String>,
password: Option<String>,
headers: &Vec<HeaderKind>,
headers: &[HeaderKind],
tag: Tag,
) -> Result<(Option<String>, UntaggedValue, Tag), ShellError> {
if location.starts_with("http:") || location.starts_with("https:") {
@ -311,20 +311,18 @@ pub async fn post(
}
None => Ok((
None,
UntaggedValue::string(format!("No content type found")),
UntaggedValue::string("No content type found".to_owned()),
Tag {
anchor: Some(AnchorLocation::Url(location.to_string())),
span: tag.span,
},
)),
},
Err(_) => {
return Err(ShellError::labeled_error(
"URL could not be opened",
"url not found",
tag,
));
}
Err(_) => Err(ShellError::labeled_error(
"URL could not be opened",
"url not found",
tag,
)),
}
} else {
Err(ShellError::labeled_error(