nushell/crates
Antoine Stevan d6141881f2
FEATURE: add the example results to the scope (#8319)
Related to #8189.
Should close #8302.

Important to:
- have a complete `$nu` structure with all available information
- generate an accurate website, because the `make_docs.nu` script of
`nushell.github.io` uses `$nu.scope.command` to generate the pages of
https://nushell.sh/commands/

> **Note**
> i was looking for "scope" in the source of `nushell` to augment
`$nu.scope` and i found `crates/nu-engine/src/scope.rs` that defines
`nu_engine::scope::create_scope` which lead me to
`nu_engine::scope::ScopeData.collect_commands`.
> i hope this is the right file 😌 

# Description
this PR slightly modifies
`nu_engine::scope::ScopeData.collect_commands`:
- add the "result" column to `$nu.scope.commands.examples`
- put the result of the example when a valid `Option(Value)`
- put a `Value::Nothing` when the result is set to `None` in the source
of the command

# User-Facing Changes
users can now access the results of all examples in
```bash
$nu.scope.commands | where name == <command> | get examples.0.result
```

## example...
### ...with a command that defines examples: `merge`
```bash
>_ $nu.scope.commands | where name == merge | get examples.0 | reject description | table --expand
╭───┬────────────────────────────────────────────────────────┬───────────────────────────╮
│ # │                        example                         │          result           │
├───┼────────────────────────────────────────────────────────┼───────────────────────────┤
│ 0 │ [a b c] | wrap name | merge ( [1 2 3] | wrap index )   │ ╭───┬──────╮              │
│   │                                                        │ │ # │ name │              │
│   │                                                        │ ├───┼──────┤              │
│   │                                                        │ │ 1 │ a    │              │
│   │                                                        │ │ 2 │ b    │              │
│   │                                                        │ │ 3 │ c    │              │
│   │                                                        │ ╰───┴──────╯              │
│ 1 │ {a: 1, b: 2} | merge {c: 3}                            │ ╭───┬───╮                 │
│   │                                                        │ │ a │ 1 │                 │
│   │                                                        │ │ b │ 2 │                 │
│   │                                                        │ │ c │ 3 │                 │
│   │                                                        │ ╰───┴───╯                 │
│ 2 │ [{columnA: A0 columnB: B0}] | merge [{columnA: 'A0*'}] │ ╭───┬─────────┬─────────╮ │
│   │                                                        │ │ # │ columnA │ columnB │ │
│   │                                                        │ ├───┼─────────┼─────────┤ │
│   │                                                        │ │ 0 │ A0*     │ B0      │ │
│   │                                                        │ ╰───┴─────────┴─────────╯ │
╰───┴────────────────────────────────────────────────────────┴───────────────────────────╯
```
and we can check that these are "true" results and not just string, e.g.
```bash
>_ $nu.scope.commands | where name == merge | get examples.0.result.0 | describe
table<name: string, index: int>
```
### ...with a command without any example: `open`
```bash
>_ $nu.scope.commands | where name == open | get examples.0 | reject description | table --expand
╭───┬──────────────────────────────────────┬────────╮
│ # │               example                │ result │
├───┼──────────────────────────────────────┼────────┤
│ 0 │ open myfile.json                     │        │
│ 1 │ open myfile.json --raw               │        │
│ 2 │ 'myfile.txt' | open                  │        │
│ 3 │ open myfile.txt --raw | decode utf-8 │        │
╰───┴──────────────────────────────────────┴────────╯
```
and same thing, we can check that there is `$nothing` in this last
command
```bash
>_ $nu.scope.commands | where name == open | get examples.0.result.0 | describe
table<name: string, index: int>
```

# Tests + Formatting
- ✔️ `cargo fmt --all`
- ✔️ `cargo clippy --workspace -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect`
- ✔️ `cargo test --workspace` (~~currently running~~)

# After Submitting
the documentation would have to be regenerated!
2023-03-05 10:56:06 +01:00
..
nu_plugin_custom_values Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu_plugin_example Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu_plugin_formats Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu_plugin_gstat Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu_plugin_inc Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu_plugin_python update nu_plugin_python due to signature changes (#8107) 2023-02-18 13:27:24 +00:00
nu_plugin_query Added examples to query web plugin (#8171) 2023-02-22 19:01:15 +00:00
nu-cli Fix CPU usage info in sys (#8321) 2023-03-04 14:48:34 -08:00
nu-cmd-lang Update the command 'version'. (#8312) 2023-03-04 16:23:30 -06:00
nu-color-config Display empty records and lists (#7925) 2023-02-22 16:18:33 +00:00
nu-command Fix CPU usage info in sys (#8321) 2023-03-04 14:48:34 -08:00
nu-engine FEATURE: add the example results to the scope (#8319) 2023-03-05 10:56:06 +01:00
nu-explore Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu-glob Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu-json README for nu-json. Related to nushell/nushell#8253 (#8289) 2023-03-03 19:07:25 -06:00
nu-parser Resolve Clippy warnings inside tests. (#8315) 2023-03-04 14:58:20 +01:00
nu-path Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu-plugin Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu-pretty-hex Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu-protocol Document and critically review ShellError variants - Ep. 1 (#8229) 2023-03-01 20:34:48 +01:00
nu-system Bump procfs from 0.14.1 to 0.15.1 (#8233) 2023-02-27 20:53:01 +13:00
nu-table table --collapse dont do truncation return message instead (#8172) 2023-02-22 18:35:45 +00:00
nu-term-grid Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu-test-support Update to 0.76.1 version for development (#8161) 2023-02-21 23:21:39 +00:00
nu-utils DOC: add a README to the standard library (#8304) 2023-03-04 08:30:36 -06:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00

Nushell core libraries and plugins

These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.

Foundational libraries are split into two kinds of crates:

  • Core crates - those crates that work together to build the Nushell language engine
  • Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.

Plugins are likewise also split into two types:

  • Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
  • Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.