From edb61fc1d590a352f1300d94740e739a70839801 Mon Sep 17 00:00:00 2001 From: YummyOreo Date: Thu, 4 May 2023 11:34:07 -0500 Subject: [PATCH] Try to show help pages for external commands w/ `help` command (#9025) # Description Makes in so if you run `std help ` it will run `man ` 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 # After Submitting --- crates/nu-std/lib/help.nu | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/nu-std/lib/help.nu b/crates/nu-std/lib/help.nu index ef2cf162ff..3702b4a8ea 100644 --- a/crates/nu-std/lib/help.nu +++ b/crates/nu-std/lib/help.nu @@ -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 }