nushell/crates/nu-command/src
WindSoilder 055edd886d
Make plugin commands support examples. (#7984)
# Description

As title, we can't provide examples for plugin commands, this pr would
make it possible


# User-Facing Changes

Take plugin `nu-example-1` as example:
```
❯ nu-example-1 -h
PluginSignature test 1 for plugin. Returns Value::Nothing

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
  (optional) opt <int>: Optional number
  ...rest <string>: rest value string

Examples:
  running example with an int value and string value
  > nu-example-1 3 bb
```

The examples session is newly added.

## Basic idea behind these changes
when nushell query plugin signatures, plugin just returns it's signature
without any examples, so nushell have no idea about the examples of
plugin commands.
To adding the feature, we just making plugin returns it's signature with
examples.

Before:
```
        1. get signature
         ----------------> 
Nushell ------------------  Plugin
        <-----------------
        2. returns Vec<Signature>
```

After:
```
        1. get signature
        ----------------> 
Nushell ------------------  Plugin
        <-----------------
        2. returns Vec<PluginSignature>
```
        
When writing plugin signature to $nu.plugin-path:
Serialize `<PluginSignature>` rather than `<Signature>`, which would
enable us to serialize examples to `$nu.plugin-path`

## Shortcoming
It's a breaking changes because `Plugin::signature` is changed, and it
requires plugin authors to change their code for new signatures.

Fortunally it should be easy to change, for rust based plugin, we just
need to make a global replace from word `Signature` to word
`PluginSignature` in their plugin project.

Our content of plugin-path is really large, if one plugin have many
examples, it'd results to larger body of $nu.plugin-path, which is not
really scale. A solution would be save register information in other
binary formats rather than `json`. But I think it'd be another story.

# 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.
2023-02-08 16:14:18 -06:00
..
bits Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
bytes Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
charting Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
conversions report which datetime couldn't be converted (#7980) 2023-02-06 14:17:07 -06:00
core_commands Fix def-env docs according to docs#761 (#7972) 2023-02-06 11:00:44 +01:00
database Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
dataframe Make plugin commands support examples. (#7984) 2023-02-08 16:14:18 -06:00
date report which datetime couldn't be converted (#7980) 2023-02-06 14:17:07 -06:00
deprecated Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
env Load env pwd (#7963) 2023-02-05 23:40:46 +01:00
experimental Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
filesystem Windows: handle illegal filenames a little better (#7999) 2023-02-07 12:30:37 -08:00
filters Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
formats Make plugin commands support examples. (#7984) 2023-02-08 16:14:18 -06:00
generators Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
hash Make plugin commands support examples. (#7984) 2023-02-08 16:14:18 -06:00
math Update few examples of math commands (#7987) 2023-02-06 13:43:00 +01:00
misc Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
network http: add --insecure flag to http get, share common code (#7992) 2023-02-07 14:22:19 -08:00
path Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
platform Validate input range of du flags (#7962) 2023-02-06 21:34:32 +01:00
random Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
shells Add more input/output type annotations (#7532) 2022-12-21 20:20:46 +01:00
strings Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
system Use imported names in Command::run signatures (#7967) 2023-02-05 22:17:46 +01:00
viewers Address #7997 (#8000) 2023-02-07 20:01:31 -06:00
default_context.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
example_test.rs Remove deprecated --numbered flag from four commands (#7777) 2023-02-02 16:59:58 -06:00
input_handler.rs Standardise the use of ShellError::UnsupportedInput and ShellError::TypeMismatch and add spans to every instance of the former (#7217) 2022-12-23 01:48:53 -05:00
lib.rs Progress bar Implementation (#7661) 2023-01-10 20:57:48 -05:00
progress_bar.rs Reduce again the number of match calls (#7815) 2023-01-24 12:23:42 +01:00
sort_utils.rs Reduce again the number of match calls (#7815) 2023-01-24 12:23:42 +01:00