mirror of
https://github.com/nushell/nushell.git
synced 2025-04-02 04:07:40 +02:00
Rename to url
command to url build-query
(#7702)
# Description Refactor command: "to url" in: "to url query". Changed usage sentence. Closes: #7495 # User-Facing Changes Now we get a query string from a record or table by using command: "to url query". ``` > help to url query Convert record or table into query string applying percent-encoding. Usage: > to url query Flags: -h, --help - Display the help message for this command Signatures: <record> | to url query -> <string> <table> | to url query -> <string> Examples: Outputs a query string representing the contents of this record > { mode:normal userid:31415 } | to url query Outputs a query string representing the contents of this 1-row table > [[foo bar]; ["1" "2"]] | to url query Outputs a query string representing the contents of this record > {a:"AT&T", b: "AT T"} | to url query ``` # Tests + Formatting Added this test: ``` Example { description: "Outputs a query string representing the contents of this record", example: r#"{a:"AT&T", b: "AT T"} | to url query"#, result: Some(Value::test_string("a=AT%26T&b=AT+T")), }, ``` to ensure percent-encoding. # After Submitting If PR is accepted I'll open another PR on documentation to notify changes on [this.](https://github.com/nushell/nushell.github.io/blob/main/book/commands/to_url.md)
This commit is contained in:
parent
a909c60f05
commit
92c4097f8d
@ -355,7 +355,6 @@ pub fn create_default_context() -> EngineState {
|
|||||||
Use,
|
Use,
|
||||||
Upsert,
|
Upsert,
|
||||||
Where,
|
Where,
|
||||||
ToUrl,
|
|
||||||
ToXml,
|
ToXml,
|
||||||
ToYaml,
|
ToYaml,
|
||||||
};
|
};
|
||||||
@ -437,6 +436,7 @@ pub fn create_default_context() -> EngineState {
|
|||||||
Fetch,
|
Fetch,
|
||||||
Post,
|
Post,
|
||||||
Url,
|
Url,
|
||||||
|
UrlBuildQuery,
|
||||||
UrlEncode,
|
UrlEncode,
|
||||||
UrlParse,
|
UrlParse,
|
||||||
Port,
|
Port,
|
||||||
|
@ -8,13 +8,11 @@ mod nuon;
|
|||||||
mod text;
|
mod text;
|
||||||
mod toml;
|
mod toml;
|
||||||
mod tsv;
|
mod tsv;
|
||||||
mod url;
|
|
||||||
mod xml;
|
mod xml;
|
||||||
mod yaml;
|
mod yaml;
|
||||||
|
|
||||||
pub use self::csv::ToCsv;
|
pub use self::csv::ToCsv;
|
||||||
pub use self::toml::ToToml;
|
pub use self::toml::ToToml;
|
||||||
pub use self::url::ToUrl;
|
|
||||||
pub use command::To;
|
pub use command::To;
|
||||||
pub use html::ToHtml;
|
pub use html::ToHtml;
|
||||||
pub use json::ToJson;
|
pub use json::ToJson;
|
||||||
|
@ -5,38 +5,47 @@ use nu_protocol::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ToUrl;
|
pub struct SubCommand;
|
||||||
|
|
||||||
impl Command for ToUrl {
|
impl Command for SubCommand {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &str {
|
||||||
"to url"
|
"url build-query"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
fn signature(&self) -> Signature {
|
||||||
Signature::build("to url")
|
Signature::build("url build-query")
|
||||||
.input_output_types(vec![
|
.input_output_types(vec![
|
||||||
(Type::Record(vec![]), Type::String),
|
(Type::Record(vec![]), Type::String),
|
||||||
(Type::Table(vec![]), Type::String),
|
(Type::Table(vec![]), Type::String),
|
||||||
])
|
])
|
||||||
.category(Category::Formats)
|
.category(Category::Network)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage(&self) -> &str {
|
fn usage(&self) -> &str {
|
||||||
"Convert record or table into URL-encoded text"
|
"Converts record or table into query string applying percent-encoding."
|
||||||
|
}
|
||||||
|
|
||||||
|
fn search_terms(&self) -> Vec<&str> {
|
||||||
|
vec!["convert", "record", "table"]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Outputs a URL string representing the contents of this record",
|
description: "Outputs a query string representing the contents of this record",
|
||||||
example: r#"{ mode:normal userid:31415 } | to url"#,
|
example: r#"{ mode:normal userid:31415 } | url build-query"#,
|
||||||
result: Some(Value::test_string("mode=normal&userid=31415")),
|
result: Some(Value::test_string("mode=normal&userid=31415")),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Outputs a URL string representing the contents of this 1-row table",
|
description: "Outputs a query string representing the contents of this 1-row table",
|
||||||
example: r#"[[foo bar]; ["1" "2"]] | to url"#,
|
example: r#"[[foo bar]; ["1" "2"]] | url build-query"#,
|
||||||
result: Some(Value::test_string("foo=1&bar=2")),
|
result: Some(Value::test_string("foo=1&bar=2")),
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: "Outputs a query string representing the contents of this record",
|
||||||
|
example: r#"{a:"AT&T", b: "AT T"} | url build-query"#,
|
||||||
|
result: Some(Value::test_string("a=AT%26T&b=AT+T")),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +119,6 @@ mod test {
|
|||||||
fn test_examples() {
|
fn test_examples() {
|
||||||
use crate::test_examples;
|
use crate::test_examples;
|
||||||
|
|
||||||
test_examples(ToUrl {})
|
test_examples(SubCommand {})
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
mod build_query;
|
||||||
mod encode;
|
mod encode;
|
||||||
mod parse;
|
mod parse;
|
||||||
mod url_;
|
mod url_;
|
||||||
@ -5,5 +6,6 @@ mod url_;
|
|||||||
use url::{self};
|
use url::{self};
|
||||||
|
|
||||||
pub use self::parse::SubCommand as UrlParse;
|
pub use self::parse::SubCommand as UrlParse;
|
||||||
|
pub use build_query::SubCommand as UrlBuildQuery;
|
||||||
pub use encode::SubCommand as UrlEncode;
|
pub use encode::SubCommand as UrlEncode;
|
||||||
pub use url_::Url;
|
pub use url_::Url;
|
||||||
|
@ -6,7 +6,7 @@ fn can_encode_and_decode_urlencoding() {
|
|||||||
cwd: "tests/fixtures/formats", pipeline(
|
cwd: "tests/fixtures/formats", pipeline(
|
||||||
r#"
|
r#"
|
||||||
open sample.url
|
open sample.url
|
||||||
| to url
|
| url build-query
|
||||||
| from url
|
| from url
|
||||||
| get cheese
|
| get cheese
|
||||||
"#
|
"#
|
||||||
|
Loading…
Reference in New Issue
Block a user