Remove the old it-hacks from fetch and post (#1807)

This commit is contained in:
Jonathan Turner
2020-05-16 11:18:46 -07:00
committed by GitHub
parent f43ed23ed7
commit 48d06f40b1
5 changed files with 12 additions and 57 deletions

View File

@ -1,7 +1,7 @@
use futures::executor::block_on;
use nu_errors::ShellError;
use nu_plugin::Plugin;
use nu_protocol::{CallInfo, ReturnValue, Signature, SyntaxShape, Value};
use nu_protocol::{CallInfo, ReturnValue, Signature, SyntaxShape};
use crate::fetch::fetch_helper;
use crate::Fetch;
@ -11,8 +11,8 @@ impl Plugin for Fetch {
Ok(Signature::build("fetch")
.desc("Load from a URL into a cell, convert to table if possible (avoid by appending '--raw')")
.required(
"path",
SyntaxShape::Path,
"URL",
SyntaxShape::String,
"the URL to fetch the contents from",
)
.switch("raw", "fetch contents as text rather than a table", Some('r'))
@ -21,20 +21,11 @@ impl Plugin for Fetch {
fn begin_filter(&mut self, callinfo: CallInfo) -> Result<Vec<ReturnValue>, ShellError> {
self.setup(callinfo)?;
Ok(vec![])
}
fn filter(&mut self, value: Value) -> Result<Vec<ReturnValue>, ShellError> {
Ok(vec![block_on(fetch_helper(
&self.path.clone().ok_or_else(|| {
ShellError::labeled_error(
"internal error: path not set",
"path not set",
&value.tag,
)
ShellError::labeled_error("internal error: path not set", "path not set", &self.tag)
})?,
self.has_raw,
value,
))])
}
}