nushell/src
Steven Xu 1d3f6105f5
feat: add a command_not_found hook (#8314)
# Description
Add a `command_not_found` function to `$env.config.hooks`. If this
function outputs a string, then it's included in the `help`.

An example hook on *Arch Linux*, to find packages that contain the
binary, looks like:

```nushell
let-env config = {
  # ...
  hooks: {
    command_not_found: {
      |cmd_name| (
        try {
          let pkgs = (pkgfile --binaries --verbose $cmd_name)
          (
            $"(ansi $env.config.color_config.shape_external)($cmd_name)(ansi reset) " +
            $"may be found in the following packages:\n($pkgs)"
          )
        } catch {
          null
        }
      )
    }
    # ...
```

# User-Facing Changes
- Add a `command_not_found` function to `$env.config.hooks`.

# 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-03-20 17:05:22 +13:00
..
tests Restrict closure expression to be something like {|| ...} (#8290) 2023-03-17 07:36:28 -05:00
command.rs feat: add a command_not_found hook (#8314) 2023-03-20 17:05:22 +13:00
config_files.rs feat: add a command_not_found hook (#8314) 2023-03-20 17:05:22 +13:00
logger.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
main.rs feat: add a command_not_found hook (#8314) 2023-03-20 17:05:22 +13:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
run.rs FEATURE: add the startup time to $nu (#8353) 2023-03-09 14:18:58 -06:00
signals.rs Cleanup of src/main.rs (#7801) 2023-01-20 10:44:49 -08:00
terminal.rs Move all functions of main.rs into modules (#7803) 2023-01-20 13:20:38 -08:00
test_bins.rs feat: add a command_not_found hook (#8314) 2023-03-20 17:05:22 +13:00
tests.rs fix: fix commandline when called with no arguments (#8207) 2023-03-16 17:45:35 -05:00

Nushell REPL

This directory contains the main Nushell REPL (read eval print loop) as part of the CLI portion of Nushell, which creates the nu binary itself.

Current versions of the nu binary will use the Nu argument parsing logic to parse the commandline arguments passed to nu, leaving the logic here to be a thin layer around what the core libraries.