mirror of
https://github.com/nushell/nushell.git
synced 2025-04-09 21:28:55 +02:00
port network url to engine-p (#3690)
migrate network URL related commands to engine-p. Part of #3390.
This commit is contained in:
parent
b1970f79ee
commit
a2dc4199d0
@ -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()),
|
||||||
)))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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))
|
||||||
|
@ -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))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user