forked from extern/nushell
Show plugin extra usage and search terms (#10952)
# Description The `PluginSignature` type supports extra usage but this was not available in `plugin_name --help`. It also supports search terms but these did not appear in `help commands` New behavior show below is the "Extra usage for nu-example-1" line and the "Search terms:" line ``` ❯ nu-example-1 --help PluginSignature test 1 for plugin. Returns Value::Nothing Extra usage for nu-example-1 Search terms: example Usage: > nu-example-1 {flags} <a> <b> (opt) ...(rest) Flags: -h, --help - Display the help message for this command -f, --flag - a flag for the signature -n, --named <String> - named string Parameters: a <int>: required integer value b <string>: required string value opt <int>: Optional number (optional) ...rest <string>: rest value string Examples: running example with an int value and string value > nu-example-1 3 bb ``` Search terms are also available in `help commands`: ``` ❯ help commands | where name == "nu-example-1" | select name search_terms ╭──────────────┬──────────────╮ │ name │ search_terms │ ├──────────────┼──────────────┤ │ nu-example-1 │ example │ ╰──────────────┴──────────────╯ ``` # User-Facing Changes Users can now see plugin extra usage and search terms # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting N/A
This commit is contained in:
parent
77fbf3e2d2
commit
81d00f71a9
@ -43,6 +43,19 @@ impl Command for PluginDeclaration {
|
||||
self.signature.sig.usage.as_str()
|
||||
}
|
||||
|
||||
fn extra_usage(&self) -> &str {
|
||||
self.signature.sig.extra_usage.as_str()
|
||||
}
|
||||
|
||||
fn search_terms(&self) -> Vec<&str> {
|
||||
self.signature
|
||||
.sig
|
||||
.search_terms
|
||||
.iter()
|
||||
.map(|term| term.as_str())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
let mut res = vec![];
|
||||
for e in self.signature.examples.iter() {
|
||||
|
@ -10,6 +10,8 @@ impl Plugin for Example {
|
||||
vec![
|
||||
PluginSignature::build("nu-example-1")
|
||||
.usage("PluginSignature test 1 for plugin. Returns Value::Nothing")
|
||||
.extra_usage("Extra usage for nu-example-1")
|
||||
.search_terms(vec!["example".into()])
|
||||
.required("a", SyntaxShape::Int, "required integer value")
|
||||
.required("b", SyntaxShape::String, "required string value")
|
||||
.switch("flag", "a flag for the signature", Some('f'))
|
||||
|
@ -1,3 +1,4 @@
|
||||
mod core_inc;
|
||||
mod custom_values;
|
||||
mod formats;
|
||||
mod register;
|
||||
|
29
tests/plugins/register.rs
Normal file
29
tests/plugins/register.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use nu_test_support::nu_with_plugins;
|
||||
use nu_test_support::playground::Playground;
|
||||
|
||||
#[test]
|
||||
fn help() {
|
||||
Playground::setup("help", |dirs, _| {
|
||||
let actual = nu_with_plugins!(
|
||||
cwd: dirs.test(),
|
||||
plugin: ("nu_plugin_example"),
|
||||
"nu-example-1 --help"
|
||||
);
|
||||
|
||||
assert!(actual.out.contains("PluginSignature test 1"));
|
||||
assert!(actual.out.contains("Extra usage for nu-example-1"));
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn search_terms() {
|
||||
Playground::setup("search_terms", |dirs, _| {
|
||||
let actual = nu_with_plugins!(
|
||||
cwd: dirs.test(),
|
||||
plugin: ("nu_plugin_example"),
|
||||
r#"help commands | where name == "nu-example-1" | echo $"search terms: ($in.search_terms)""#
|
||||
);
|
||||
|
||||
assert!(actual.out.contains("search terms: [example]"));
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user