Files
Darren Schroeder f11c5f84ed disallow keywords from being shadowed (#18662)
<!--
Thanks for contributing to Nushell!

Before submitting, please read the contributing guide:
https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md

This template helps reviewers understand your changes and allows us to
generate high-quality release notes.
-->

## Description
This PR disallows keywords from being shadowed such as `def def [] {}`.
I'm calling this a breaking change because we had to change `toolkit
run` to `toolkit dev` because `run` is now a keyword.

<!--
Explain what this PR does and why.

This section is intentionally flexible:
- Describe the problem
- Explain your approach
- Include technical details if relevant

Good examples:
- "In this PR, I fixed..."
- "In this PR, I added support for..."
- "This change improves X by..."

Write as much or as little as needed for reviewers to understand your
changes.
-->

## User-facing changes (Release notes)
Trying to shadow a keyword will produce an error now.
```nushell
❯ def def [] {}
Error: nu::parser::name_is_keyword

  × Can't use parser keyword `def` as command name.
   ╭─[repl_entry #1:1:5]
 1 │ def def [] {}
   ·     ─┬─
   ·      ╰── 'def' is a parser keyword
   ╰────
  help: Parser keywords cannot be shadowed (including via module exports and `use *`). Choose a different command name so language
        constructs keep working.
```
<!--
This section is used (mostly as-is) for https://www.nushell.sh/blog/

Describe how Nushell behavior changes from a user's perspective.
Do NOT describe internal Rust changes here.

Write in a release note style, for example:
- "Added support for..."
- "Fixed an issue where..."
- "Nushell now supports..."
- "Improved performance of..."

If your changes do NOT affect users (internal refactors, cleanup, etc.),
just write:
- "n/a"
- "nan"
- or similar

This tells us the change should not appear in the changelog.

Tips:
- Focus on observable behavior
- Include examples if helpful
- Keep it concise

You can:
- Write a short paragraph (will appear as a bullet point), OR
- Use headings (###) if your change needs more structure

Avoid writing things like:
- "In this PR, I refactored..."
- "This updates internal code..."

You may leave this blank until the PR is ready.
-->

## Additional notes
<!--
Optional.

Examples:
- fixes #123
- closes #456
- related #789

Anything else reviewers should know.
Remove this section if not needed.
-->
2026-07-19 19:05:06 -05:00

114 lines
3.2 KiB
Nu

# Run nushell from source with a right indicator.
@category "toolkit"
@search-terms run cargo run source development dev
@example "Run Nushell from source" { toolkit dev }
@example "Run with experimental options enabled" { toolkit dev --experimental-options "dataframe" }
export def dev [
--experimental-options: oneof<list<string>, string> # enable or disable experimental options
] {
let experimental_options_arg = $experimental_options
| default []
| [$in]
| flatten
| str join ","
| $"[($in)]"
^cargo run -- ...[
--experimental-options $experimental_options_arg
-e "$env.PROMPT_COMMAND_RIGHT = $'(ansi magenta_reverse)trying Nushell inside Cargo(ansi reset)'"
]
}
def build-nushell [features: string] {
print $'(char nl)Building nushell'
print '----------------------------'
^cargo build --features $features --locked
}
def build-plugin [] {
let plugin = $in
print $'(char nl)Building ($plugin)'
print '----------------------------'
cd $"crates/($plugin)"
^cargo build
}
# Build Nushell and plugins with some features.
@category "toolkit"
@search-terms build compile cargo build features plugins
@example "Build Nushell with default features" { toolkit build }
@example "Build Nushell and all plugins" { toolkit build --all }
@example "Build with specific features" { toolkit build extra stable --all }
export def build [
...features: string@"nu-complete list features" # a space-separated list of feature to install with Nushell
--all # build all plugins with Nushell
] {
build-nushell ($features | default [] | str join ",")
if not $all {
return
}
let plugins = [
nu_plugin_inc,
nu_plugin_gstat,
nu_plugin_query,
nu_plugin_polars,
nu_plugin_example,
nu_plugin_custom_values,
nu_plugin_formats,
]
for plugin in $plugins {
$plugin | build-plugin
}
}
def "nu-complete list features" [] {
open Cargo.toml | get features | transpose feature dependencies | get feature
}
def install-plugin [] {
let plugin = $in
print $'(char nl)Installing ($plugin)'
print '----------------------------'
^cargo install --path $"crates/($plugin)"
}
# Install Nushell and features you want.
@category "toolkit"
@search-terms install cargo install features plugins
@example "Install Nushell with default features" { toolkit install }
@example "Install Nushell and all plugins" { toolkit install --all }
@example "Install with specific features" { toolkit install extra stable --all }
export def install [
...features: string@"nu-complete list features" # a space-separated list of feature to install with Nushell
--all # install all plugins with Nushell
] {
touch crates/nu-cmd-lang/build.rs # needed to make sure `version` has the correct `commit_hash`
^cargo install --path . --features ($features | default [] | str join ",") --locked --force
if not $all {
return
}
let plugins = [
nu_plugin_inc,
nu_plugin_gstat,
nu_plugin_query,
nu_plugin_polars,
nu_plugin_example,
nu_plugin_custom_values,
nu_plugin_formats,
]
for plugin in $plugins {
$plugin | install-plugin
}
}