port network url to engine-p (#3690)

migrate network URL related commands to engine-p.

Part of #3390.
This commit is contained in:
Eli Flanagan 2021-06-25 21:19:10 -04:00 committed by GitHub
parent b1970f79ee
commit a2dc4199d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 13 deletions

View File

@ -1,7 +1,7 @@
use crate::prelude::*; use crate::prelude::*;
use nu_engine::WholeStreamCommand; use nu_engine::WholeStreamCommand;
use nu_errors::ShellError; use nu_errors::ShellError;
use nu_protocol::{ReturnSuccess, Signature, UntaggedValue}; use nu_protocol::{Signature, UntaggedValue};
pub struct Url; pub struct Url;
@ -18,10 +18,10 @@ impl WholeStreamCommand for Url {
"Apply url function." "Apply url function."
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
Ok(ActionStream::one(ReturnSuccess::value( Ok(OutputStream::one(
UntaggedValue::string(get_full_help(&Url, args.scope())).into_value(Tag::unknown()), UntaggedValue::string(get_full_help(&Url, args.scope())).into_value(Tag::unknown()),
))) ))
} }
} }

View File

@ -22,7 +22,7 @@ impl WholeStreamCommand for UrlHost {
"gets the host of a url" "gets the host of a url"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
let rest: Vec<ColumnPath> = args.rest(0)?; let rest: Vec<ColumnPath> = args.rest(0)?;
let input = args.input; let input = args.input;

View File

@ -6,7 +6,7 @@ mod scheme;
use crate::prelude::*; use crate::prelude::*;
use nu_errors::ShellError; use nu_errors::ShellError;
use nu_protocol::{ColumnPath, Primitive, ReturnSuccess, ShellTypeName, UntaggedValue, Value}; use nu_protocol::{ColumnPath, Primitive, ShellTypeName, UntaggedValue, Value};
use url::Url; use url::Url;
pub use command::Url as UrlCommand; pub use command::Url as UrlCommand;
@ -37,14 +37,14 @@ where
Ok(v) Ok(v)
} }
fn operate<F>(input: crate::InputStream, paths: Vec<ColumnPath>, action: &'static F) -> ActionStream fn operate<F>(input: crate::InputStream, paths: Vec<ColumnPath>, action: &'static F) -> OutputStream
where where
F: Fn(&Url) -> &str + Send + Sync + 'static, F: Fn(&Url) -> &str + Send + Sync + 'static,
{ {
input input
.map(move |v| { .map(move |v| {
if paths.is_empty() { if paths.is_empty() {
ReturnSuccess::value(handle_value(&action, &v)?) handle_value(&action, &v)
} else { } else {
let mut ret = v; let mut ret = v;
@ -55,8 +55,8 @@ where
)?; )?;
} }
ReturnSuccess::value(ret) Ok(ret)
} }
}) })
.into_action_stream() .into_input_stream()
} }

View File

@ -22,7 +22,7 @@ impl WholeStreamCommand for UrlPath {
"gets the path of a url" "gets the path of a url"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
let rest: Vec<ColumnPath> = args.rest(0)?; let rest: Vec<ColumnPath> = args.rest(0)?;
let input = args.input; let input = args.input;

View File

@ -22,7 +22,7 @@ impl WholeStreamCommand for UrlQuery {
"gets the query of a url" "gets the query of a url"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
let rest: Vec<ColumnPath> = args.rest(0)?; let rest: Vec<ColumnPath> = args.rest(0)?;
let input = args.input; let input = args.input;
Ok(operate(input, rest, &query)) Ok(operate(input, rest, &query))

View File

@ -21,7 +21,7 @@ impl WholeStreamCommand for UrlScheme {
"gets the scheme (eg http, file) of a url" "gets the scheme (eg http, file) of a url"
} }
fn run_with_actions(&self, args: CommandArgs) -> Result<ActionStream, ShellError> { fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
let rest: Vec<ColumnPath> = args.rest(0)?; let rest: Vec<ColumnPath> = args.rest(0)?;
Ok(operate(args.input, rest, &Url::scheme)) Ok(operate(args.input, rest, &Url::scheme))
} }