Try to show help pages for external commands w/ help command (#9025)

# 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.
-->
Makes in so if you run `std help <external>` it will run `man <command>`
to get help pages. This command is configurable w/ the `$env.NU_HELPER`
var.

This will close #8032

Examples:
`std help rg` will display the ripgrep help pages

Todo:
- [x] Make flags and fallback configurable
- [x] Improve the warning that it is external
- [ ] Implement `--find` for external commands

# User-Facing Changes
Users will now be able to run `std help` on external commands

# 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 -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# 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.
-->
This commit is contained in:
YummyOreo 2023-05-04 11:34:07 -05:00 committed by GitHub
parent 155de9f6fc
commit edb61fc1d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -653,16 +653,17 @@ def show-command [command: record] {
print ""
}
# Show help on nushell commands.
# Show help on commands.
export def "help commands" [
...command: string@"nu-complete list-commands" # the name of command to get help on
--find (-f): string # string to find in command names and usage
] {
let commands = ($nu.scope.commands | where not is_extern | reject is_extern | sort-by name)
let commands = ($nu.scope.commands | where not is_extern | reject is_extern | sort-by name )
let command = ($command | str join " ")
if not ($find | is-empty) {
# TODO: impl find for external commands
let found_commands = ($commands | find $find --columns [name usage search_terms])
if ($found_commands | length) == 1 {
@ -671,13 +672,19 @@ export def "help commands" [
$found_commands | select name category usage signatures search_terms
}
} else if not ($command | is-empty) {
let found_command = ($commands | where name == $command)
let found_commands = ($commands | where name == $command)
if ($found_command | is-empty) {
command-not-found-error (metadata $command | get span)
if not ($found_commands | is-empty) {
show-command ($found_commands | get 0)
} else {
try {
print $"(ansi default_italic)Help pages from external command ($command | pretty-cmd):(ansi reset)"
^($env.NU_HELPER? | default "man") $command
} catch {
command-not-found-error (metadata $command | get span)
}
}
show-command ($found_command | get 0)
} else {
$commands | select name category usage signatures search_terms
}