Skip to content

Commit

Permalink
Add completer for std help (#12929)
Browse files Browse the repository at this point in the history
# Description

While each of the `help <subcommands>` in `std` had completers, there
wasn't one for the main `help` command.

This adds all internals and custom commands (as with `help commands`) as
possible completions.

# User-Facing Changes

`help ` + <kbd>Tab</kbd> will now suggest completions for both the `help
<subcommands>` as well as all internal and custom commands.

# Tests + Formatting

Note: Cannot add tests for completion functions since they are
module-internal and not visible to test cases, that I can see.

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
  • Loading branch information
NotTheDr01ds committed May 21, 2024
1 parent 1cdc39b commit f83439f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crates/nu-std/std/help.nu
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def "nu-complete list-commands" [] {
scope commands | select name usage | rename value description
}

def "nu-complete main-help" [] {
[
{ value: "commands", description: "Show help on Nushell commands." }
{ value: "aliases", description: "Show help on Nushell aliases." }
{ value: "modules", description: "Show help on Nushell modules." }
{ value: "externs", description: "Show help on Nushell externs." }
{ value: "operators", description: "Show help on Nushell operators." }
{ value: "escapes", description: "Show help on Nushell string escapes." }
]
| append (nu-complete list-commands)
}

def "nu-complete list-externs" [] {
scope commands | where is_extern | select name usage | rename value description
}
Expand Down Expand Up @@ -720,7 +732,7 @@ def pretty-cmd [] {
# search for string in command names, usage and search terms
# > help --find char
export def main [
...item: string # the name of the help item to get help on
...item: string@"nu-complete main-help" # the name of the help item to get help on
--find (-f): string # string to find in help items names and usage
] {
if ($item | is-empty) and ($find | is-empty) {
Expand Down

0 comments on commit f83439f

Please sign in to comment.