diff --git a/crates/nu_plugin_query/src/nu/mod.rs b/crates/nu_plugin_query/src/nu/mod.rs index 65ca0e4c2e..27ce7a4b98 100644 --- a/crates/nu_plugin_query/src/nu/mod.rs +++ b/crates/nu_plugin_query/src/nu/mod.rs @@ -1,6 +1,6 @@ use crate::Query; 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 { fn signature(&self) -> Vec { @@ -23,6 +23,7 @@ impl Plugin for Query { .usage("execute selector query on html/web") .named("query", SyntaxShape::String, "selector query", Some('q')) .switch("as-html", "return the query output as html", Some('m')) + .plugin_examples(web_examples()) .named( "attribute", SyntaxShape::String, @@ -68,3 +69,26 @@ impl Plugin for Query { } } } + +pub fn web_examples() -> Vec { + vec![PluginExample { + example: "http get https://phoronix.com | query web -q 'header'".into(), + description: "Retrieve all
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, + }] +}