mirror of
https://github.com/nushell/nushell
synced 2024-12-25 12:33:17 +00:00
Added examples to query web plugin (#8171)
# Description _(Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes.)_ _(Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience.)_ # User-Facing Changes _(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)_ # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --------- Co-authored-by: Yethal <nosuchemail@email.com>
This commit is contained in:
parent
8deecc0137
commit
f4a129a792
1 changed files with 25 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::Query;
|
use crate::Query;
|
||||||
use nu_plugin::{EvaluatedCall, LabeledError, Plugin};
|
use nu_plugin::{EvaluatedCall, LabeledError, Plugin};
|
||||||
use nu_protocol::{Category, PluginSignature, Spanned, SyntaxShape, Value};
|
use nu_protocol::{Category, PluginExample, PluginSignature, Spanned, SyntaxShape, Value};
|
||||||
|
|
||||||
impl Plugin for Query {
|
impl Plugin for Query {
|
||||||
fn signature(&self) -> Vec<PluginSignature> {
|
fn signature(&self) -> Vec<PluginSignature> {
|
||||||
|
@ -23,6 +23,7 @@ impl Plugin for Query {
|
||||||
.usage("execute selector query on html/web")
|
.usage("execute selector query on html/web")
|
||||||
.named("query", SyntaxShape::String, "selector query", Some('q'))
|
.named("query", SyntaxShape::String, "selector query", Some('q'))
|
||||||
.switch("as-html", "return the query output as html", Some('m'))
|
.switch("as-html", "return the query output as html", Some('m'))
|
||||||
|
.plugin_examples(web_examples())
|
||||||
.named(
|
.named(
|
||||||
"attribute",
|
"attribute",
|
||||||
SyntaxShape::String,
|
SyntaxShape::String,
|
||||||
|
@ -68,3 +69,26 @@ impl Plugin for Query {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn web_examples() -> Vec<PluginExample> {
|
||||||
|
vec![PluginExample {
|
||||||
|
example: "http get https://phoronix.com | query web -q 'header'".into(),
|
||||||
|
description: "Retrieve all <header> elements from phoronix.com website".into(),
|
||||||
|
result: None,
|
||||||
|
}, PluginExample {
|
||||||
|
example: "http get https://en.wikipedia.org/wiki/List_of_cities_in_India_by_population
|
||||||
|
| query web -t [Rank City 'Population(2011)[3]' 'Population(2001)' 'State or union territory']".into(),
|
||||||
|
description: "Retrieve a html table from Wikipedia and parse it into a nushell table using table headers as guides".into(),
|
||||||
|
result: None
|
||||||
|
},
|
||||||
|
PluginExample {
|
||||||
|
example: "http get https://www.nushell.sh | query web -q 'h2, h2 + p' | group 2 | each {rotate --ccw tagline description} | flatten".into(),
|
||||||
|
description: "Pass multiple css selectors to extract several elements within single query, group the query results together and rotate them to create a table".into(),
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
|
PluginExample {
|
||||||
|
example: "http get https://example.org | query web --query a --attribute href".into(),
|
||||||
|
description: "Retrieve a specific html attribute instead of the default text".into(),
|
||||||
|
result: None,
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue